MVC :: Unable To Redirect To Action When Posting With Json?

Nov 8, 2010

I originally have the question posted here, but I need as many eyes as possible on it.Essentially, I'm having issues redirecting to an action in mvc2 when working with JSON data. I post a stringified JSON object to an action and the action in turn redirects as needed. It worked previously when using form fields, but not when I'm posting JSON. To get posted JSON objects to properly bind to parameters objects in MVC, I'm taking advantage of the JsonValueProviderFactory class from MVC2Futures/MVC3Beta.Why is this occuring? The jQuery ajax call is telling the server "I'm giving you json, I expect html in return" and all actions pointed to via RedirectToAction calls are structured in a similar manner. I instead get stuck in a loop, continually hitting the originally requested action, with a prompt to reenter authorization information to boot! It seems lose authentication/authorization information in the process.The linked question on

View 4 Replies


Similar Messages:

MVC :: Redirect Action Not Working In Jqgrid Action Results Method

Mar 23, 2011

I am desiging a master and details page from a search page..user can search for something and I need to display the result in jqgrid if the result has more than 1 row or record.. if the result is just one record then i have to directly send then to details page by skiping grid page... I do have an action method for results page and one more action method for Jqgrid data..i am trying to check the row count for the database result and trying to redirect to details action results..but its not working at all..and showing an empty jqgrid..

[Code]....

View 9 Replies

Posting HTML In An MVC Action?

May 7, 2010

So I have a form with a text area on it, and I need to post it. I can't encode it (as far as I know) client side, prior to submit, and it causes the yellow screen of death before reaching the HttpPost action handler.

View 4 Replies

AJAX :: Posting JSon To MVC ActionResult?

Feb 14, 2011

I am lost, I am posing a jSon result to an MVC ActionResult and I cannot get it done. What I have is on the View:

[Code]....

With Firebug I can see that I am posting a jSon result with the result I selected. This result is comming from a select list(UnAssignedPages) as the items selected.

Now I want to iterate over that list in the controller and I cannot find an example of how to do it? I found a jSon value provider from Phil Haack [URL] but I was specifically told not to use the Futures Library. Is there any example of how to accept a jSon result in an ActionResult?

View 3 Replies

MVC :: InvalidCastException When Posting Address Data To Action?

May 7, 2010

I have a Person class with an Address property. The Address contains a Country property of type Country which in turn has a CountryCode property of type string, as follows:

Person.Address.Country.CountryCode

I have a select element on the page with a name of "Country.CountryCode". With MVC 1 this was bound perfectly to the CountryCode property of Country. In MVC 2 however, I get the following error when the page is posted back:

[Code].....

View 9 Replies

JQuery :: To Supply An AntiForgeryToken When Posting JSON Data?

May 25, 2010

I am using the code as below of this post:First i will an fill array variable with the correct values for the controller action.Using the code below i think it should be very straigtforward by just adding the following line to the javascript:

data["__RequestVerificationToken"] = $('[name=__RequestVerificationToken]').val();
The <%= Html.AntiForgeryToken() %> is at his right place and the action has a [ValidateAntiForgeryToken]

But my controller action keeps saying: "Invalid forgery token"


====================CODE=======================

data["fiscalyear"] = fiscalyear;
data["subgeography"] = $(list).pa n

[code]....

View 1 Replies

MVC :: How To Supply A Antiforgerytoken When Posting JSON Data Using $.ajax

May 25, 2010

I am using the code as below of this post:First i will an fill array variable with the correct values for the controller action.Using the code below i think it should be very straigtforward by just adding the following line to the javascript:

data["__RequestVerificationToken"] = $('[name=__RequestVerificationToken]').val();
<%= Html.AntiForgeryToken() %> is at his right place and the action has a [ValidateAntiForgeryToken]

But my controller action keeps saying: "Invalid forgery token

View 2 Replies

MVC :: Posting List Of Checked Items To Controller Action Using JQuery Post?

Feb 16, 2011

I got a list of checkboxes on my form, and a jquery script that catch a button click to get all the selected items (in an array) and post to a controller action.

This is my script: (yes A, looked at your sample but cannot get this to work)

[Code]....

That alert will print out correctly (like 1,3,5).

However when the above post hit my controller action, "selectedInvestments" are null, which I can't figure out why (back to my tekpub jquery videos, can't go on like this)

[Code]....

View 3 Replies

After Posting Comment Automatically Redirect To Blog?

May 10, 2010

I have embedded a Google Blog to my website using iFrame and its working well, now i allow people to post comments anonymously and its working fine, now the problem comes when someone post a comment, after the comment has been posted, this will navigate away from my website and it will only take the user to the blog. How do i prevent that, after the posting it still stay in my site.

View 16 Replies

How To Pass JSON To Controller Action

Mar 6, 2011

I have some textboxes and a table of data created client side that I want pass to a controller as JSON.

I want to use Jquery to enumerate the table.

Assume I have 2 textboxes called name and age. Assume a table with 2 columns. one column with class called phonetype and one column class called phonenumber.

So how do construct the JSON from this?

View 1 Replies

Jquery - Get Json Data In Controller Action?

Feb 9, 2011

I have asp.net mvc application. i want to configure the object in jquery and want to pass it to the the action of controller . where as in my script i am using this for configure data for the ajax call:

[Code]....

it does not calls to action in controller. i think here :

var json = $.toJSON(peform);

is not working as expect. is it need to add any js file to reference ? or mistake in syntax?

View 1 Replies

Javascript - Passing JSON To Controller Action

Mar 7, 2011

I have the following javascript. Problem is if I enter one row in the table "ingredients" but I am getting 2 rows in the resulting pass to controller action after seralising into my C# object. But the second object is null? I checked the javascript and the variable "cnt" is 1 not 2. Why would that be?

[code]

$("#Save").click(function () {
var title = $("#recipetitle").val();
var category = $("#category").val();
var preptime = $("#prepTime").val();
var preptimeperiod = $("#lstPrepTime").val();
var cooktime = $("#cookTime").val();
var cooktimeperiod = $("#lstCookTime").val();
var rating = $("#rating").val();
var method = $("#method").val();
var jsontext = '{ "RecipeTitle": "' + title + '",';
jsontext += '"CategoryID":' + category + ',';
jsontext += '"PrepTime":' + preptime + ',';
jsontext += '"PrepTimePeriod":"' + preptimeperiod + '",';
jsontext += '"CookTime":' + cooktime + ',';
jsontext += '"CookTimePeriod":"' + cooktimeperiod + '",';
jsontext += '"Rating":' + rating + ',';
jsontext += '"Method":"' + method + '",';....................

View 1 Replies

C# - How To Return Json From Action Method With Array Property

Mar 14, 2011

I am trying to return some data as json from an action method.

I have an employee object that looks like this:

public class Employee
{
public int EmployeeID {get; set;}
public string FirstName {get; set;}
public string LastName {get; set;}
//Other irrelevant properties
}

Then I have a view model as follows

public Class EmployeeViewModel
{
public Employee Supervisor{get; set;}
public List<EmployeeViewModel> Employees
}

I need to return a json object that looks exactly like this:

{id: 1, name: John, children: [
{id: 1, name: Joe, children: []},
{id: 1, name: Rob, children: []}
]}

For now I only need to go to the second level as above, returning and supervisor and their staff members beneath them.

How would I go about returning this in my action method(I have the viewModel object hydrated already I just need to return it as json). My problem so far has been that the children property does not get populated.

View 1 Replies

Configuration :: Mvc Action Not Showing Json Data As Required?

Oct 13, 2010

wrote an MVC 2 action which shows json data in the browser when i browse to the URL in my Dev environment.

When i upload it to production and i browse to the same url, i get;

04 - File or directory not found.The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.I have decorated the action with httpget and the url is in the format;
[URL]is the same format in my Dev Environment too..

View 4 Replies

Passing Complex JSON Data JQuery To Action?

Dec 1, 2010

I have 2 classes that are used to mirror the data from an ajax call. One (Customer) contains a property which is name, and the other is an array of Products.

Public Class Customer
Private _Name as String
Private _Products as Product()
Public Property Name() As String

[Code].....

View 1 Replies

MVC :: Passing Json Collection Object From View To Action

Nov 1, 2010

I am trying to send json data from view to controller action. But the issue is the data is not populating in the action parameter List<Score>.

View Model:
public class Score
{
public int QuestionId { get; set; }
public int PrevAnswerId { get; set; }
public int CurrAnswerId { get; set; }
public string CurrAnswerName { get; set; }
}

Json Data look like:
[
{QuestionId:1, PrevAnswerId:3, CurrAnswerId:3, CurrAnswerName:'Known to Broker'},
{QuestionId:2, PrevAnswerId:7, CurrAnswerId:7, CurrAnswerName:'Completed'},
{QuestionId:3, PrevAnswerId:10, CurrAnswerId:10, CurrAnswerName:'Report'}
]

On window load, I will construct the Json object using "eval()" function and do some operation in the data before its save. On Save Click, I will call the action through the ajax call.

$.ajax({
url: url,
type: "GET",
dataType: 'json',
data: {score: ScoreJson},
contentType: "application/json; charset=utf-8",
success: function () {
alert("succes");
},
error: function () {
alert("error...");
} });

Action:
public ActionResult SaveScore(List<Score> score)
{
// do something...
}

But here score comming as collection of 3 elements with zero(for interger property)/null(for string property) values. When I checked in the request I found the data in "parama" property like.

"Score%5b0%5d%5bQuestionId%5d=1 &Score%5b0%5d%5bPrevAnswerId%5d=3 &Score%5b0%5d%5bCurrAnswerId%5d=3 &Score%5b0%5d%5bCurrAnswerName%5d=Known+to+broker&
Score%5b1%5d%5bQuestionId%5d=2 &Score%5b1%5d%5bPrevAnswerId%5d=7 &Score%5b1%5d%5bCurrAnswerId%5d=7 &Score%5b1%5d%5bCurrAnswerName%5d=Completed&
Score%5b2%5d%5bQuestionId%5d=3 &Score%5b2%5d%5bPrevAnswerId%5d=10 &Score%5b2%5d%5bCurrAnswerId%5d=10 &Score%5b2%5d%5bCurrAnswerName%5d=Travelers+Report&".

But I am not sure why it is not getting populated in the score list. One full day I spent for this issue but till now I didnt find the solution for this issue.

View 4 Replies

MVC :: How To Redirect From Action To Another Action

Feb 3, 2011

I have a page with three partial views. On the first ascx, I want some data posted when a user clicks on "submit" button, and send that data to another POST action "search" and search the db with that data, the final output should be the view returned by "search". How do I do this?

View 3 Replies

Javascript - How To Pass Json Collection Object To Mvc Controller Action Method

Dec 21, 2010

I am creating one Json array object and trying to pass it in MVC controller action method but i am getting null paramerter; as per my knowledge json only maps .net primitive datatypes.... so it assign null value.

Note: when i have look at request object i found that there are three parameter of created array. But how to get that value as parameter of function?

View 2 Replies

"Failed To Load Source" Posting To MVC2 Action With JQuery

Sep 19, 2010

I am trying to save user feedback by using jquery to post to an action however i am getting the error message "Failed to load source for: http://www.something.com/feedback/savefeedback" this code works fine on localhost but not when put on my shared hosting, this doesnt just affect this query post but also at least one other.

below i have the route from the global.ascx, the action int the FeedBackController and the query that does the post.

routes.MapRoute(
"FeedBack", // Route name
"FeedBack/{action}", // URL with parameters [code]....

View 9 Replies

MVC :: Redirect To Action By Jquery?

Apr 8, 2010

how can i redirect to an action by jquery

View 2 Replies

How To Perform A Javascript Action Right After Redirect

Mar 9, 2011

After a user creates an account on my website, I want to redirect the user to the home page and display a twitter style message bar on top. This is how I have it:

success: function (response) {
if (response.Success) {
location.href = response.ReturnUrl;
}
ShowMessageBar(response.Message);
},

The message bar does appear but it gets displayed only for a second as it gets canceled by the redirect. What can I do to display the message right after the redirect has completed? Is there a complete event for the location.href?

View 6 Replies

MVC :: Redirect To Post Method/Action?

Mar 28, 2011

I have an ActionResult that accepts POST, however is there a work around for me to redirect from a controller to another controller containing this POST method/action?

View 3 Replies

C# - Redirect User Back To The Original Action After Login

Jan 26, 2011

The sequence of actions that I am trying to accomplish is below.

Context: user can add products to its own account.

User tries to add a specific product. (He/she is not login at this point.

In the code behind, I need to redirect the user to login page before I can add the product to user's account.

After login, how do I take the system back to the logic to finish up the action in step 1.

View 2 Replies

AJAX :: Unable To Use Wcf Service With Json

Feb 13, 2010

I have developed a wcf service for asp.net ajax client. It includes the following steps.

(1) Created WCF sevice contract with the operation "DoWork()" which will take string as input and retun string as output.

(2)Implemented the above operation contract(attributed the implementation class with aspnetcompatibility requirement as enabled).

(3)Added the webscriptenabled to endpoint in web.config file.

(4)Hosted the wcf servie.

(5)Downloaded the javascript file from the service.(e.g.,http://localhost/service1.svc/js)

Client

(1)Opend new asp.net webapplication.

(2)Added the downloaded .js file.

(3)Given the scripts path for ajaxscript manager as both .js file and service url.

e.g

<asp:ScriptManager
ID="id1"
runat="server">
<Scripts>
<asp:ScriptReference
Path="http://localhost:3443/Service1.svc/js/"
/>
<asp:ScriptReference
Path="~/js1.js"
/>
</Scripts>
</asp:ScriptManager>

(4)With this I am unable to call service method

View 2 Replies

Unable To Get Values From JSON Converted From XML?

Apr 21, 2010

I have passed some JSON to my page via a webservice. I used JSON.NET to convert XML to JSON. The JSON output looks ok to me, but I am unable to access some of the items in the response. I am not sure why it is not working. I am using jQuery to read the response and make the webservice call. Even when I try to read the length of the array it says 'undefined'

function GetFeed(){
document.getElementById("marq").innerHTML = '';
$.ajax({
type: "POST",

[Code]....

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved