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


Similar Messages:

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

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

Passing Form Data To Mvc Controller Action Using JQuery?

Feb 3, 2010

Basically, I have an HTML Form and would want to pass the data from the form to n asp.net mvc controller, then the controller would return an XML for client side manipulation.

Here is my initial code:

[Code]....

When I run and debug, I get a message that says "attr(..) is null or not an object. I am still trying to learn web development using ASP.NET MVC.

View 3 Replies

Passing JSON From JQuery To ASHX?

Jun 1, 2010

I'm trying to pass JSON from jQuery to a .ASHX file. Example of the jQuery below:

$.ajax({
type: "POST",
url: "/test.ashx",
data: "{'file':'dave', 'type':'ward'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
});

How do I retrieve the JSON data in my .ASHX file? I have the method:

public void ProcessRequest(HttpContext context)

but I can't find the JSON values in the request.

View 5 Replies

Passing ID Of Element To A C# Web Service (using JSON) From JQuery?

Mar 9, 2010

I have an containing a list of divs that jQuery turns into progress bars. On .ready, I build a list of all of these progress bars and for each one, call a webservice that gets a value indicating how full the progress bar should be. In order to do this, I need to pass the ID of the div to the web service.

Because the divs are inside a ListView, I manually set the id to be id="completionbar_<%# Eval("MilestoneID") %>"

However, when I pass this id into my web service, it comes up as "undefined" every time. When I view the source, it looks like it's set correctly.

Here's the jQuery that calls my web service:

<script type="text/javascript" language="javascript">
$(document).ready(function() {
$(".MilestoneCompletion").progressbar({ value: 0 });
$.each($(".MilestoneCompletion"), function(index, barDiv) {

[Code].....

I'm thinking maybe the script is executing before the DIV id is set by the ListView databind?

View 2 Replies

JQuery Ajax With MVC Action - Passing Arguments From JavaScript In POST

Mar 4, 2011

I have an ASP.NET MVC controller action with the following VB.NET signature:

<HttpPost()>
Public Function ClosestCities
(ByVal position As MapCoordinate, ByVal citiesCount As UInteger) As JsonResult

The MapCordinate class is:

Public Class MapCoordinate
Public Latitude As Double
Public Longitude As Double
End Class

If I'm trying to send an Ajax POST in jQuery to the ClosestCities action, what should my request look like?

When I use the following code to POST to this action, in the debugger window of VS, position.longitiude and position.latitude are equal to 0.0 (0D):

[code]....

View 2 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

AJAX :: Return Complex Type In Json Format?

Jun 11, 2010

I was using Extjs to send a json object to my asp.net webservice/Update method , but I find the following error in firebug reseponse.

[Code]....

View 1 Replies

MVC :: Modify Parameter Of Complex Type In Action Filter?

Feb 25, 2010

I thought this would be easy and maybe it is but it's eluding me.

In an action filter (MVC 2) I want to add/edit one of the parameters for the type I'm passing to my action method.

I have an action method:

[Code]....

Bar is a simple class for viewData:

[Code]....

In my BarFilter action filter OnActionExecuting method I want to add a value for paramA which is not set by the view so that Bar will be fully populated in my Foo action method. I've tried various methods of adding values to ViewData, ModelState, Model etc. but I always get a null returned in Foo.

View 3 Replies

Passing JSON Data To A Webservice?

Jul 8, 2010

I have two parameters (categoryName and categoryDescription) that I need to pass to the web service using JSON. I found the syntax to pass categoryName but have not been able to get the correct syntax to pass both parameters. Here is the code.

<script src="js/jquery-1.4.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {

[code]...

View 4 Replies

Vb.net - Passing Data To Webservice Using JSON?

Jun 22, 2010

I have successfully returned data from a ASP.Net webservice in JSON format (using a service method that required no parameters) but have struggled with making a webservice call that requires a parameter.

Webservice:

<WebMethod()> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=True)> _
Public Function TestWebService(ByVal Description As String) As Stock
Dim res As New Stock(Guid.NewGuid, Description)
Return res

[Code]....

View 1 Replies

C# - Passing JSON Serialized Data Via Hidden Field?

Mar 2, 2011

In ASP.NET WebForms I want to pass arbitrary data from server to client and back again. I am serializing to JSON and have been simply producing JavaScript that creates the object on the client. I have no problem sending data to the server with ajax, but there are situations where I also want to send a Javascript object data back to the server on postbacks. So I guess it needs to be in a hidden field.

1) What is the best way to do this in terms of minimizing complexity and optimizing space and efficiency? In researching this I discovered Protocol Buffers but there does not seem to be a good C# implementation. I did find one, but it was a couple years old and self-described as buggy so that scared me.

2) If I just pass a JSON string, how can I be sure it will be safe to include as the value for a hidden field? Is there any reason I might not want to do this? I could Base64 encode, but it seems like this adds a lot of overhead. What is considered the best or preferred method?

View 1 Replies

Passing Data From Controller To View Using JSon Object

Mar 4, 2011

I have the following to get the Json abject passed from the controller and populate the various textboxes in the view. However, nothing is happening even though controller is passing a valid Json object. What is wrong with this code?

<script language="javascript" type="text/javascript">
$(document).ready(function() {
var url = '<%=Url.Action("DropDownChange") %>';
$("#vendorID").change(function() {
var selectedID = $(this).val();
if (selectedID != "New Vendor Id") {
//$.post('Url.Action("DropDownChange","Refunds")', function(result) {
$.post(url, { dropdownValue: selectedID }, function(result) {
alert(selectedID);
$("#name").val(result.Name);
$("#city").val(result.City);
$("#contact").val(result.Contact);
$("#address2").val(result.Address2);
$("#address1").val(result.Address1);
$("#state").val(result.State);
$("#zip").val(result.Zip);
});
}
});
});
This is the code in my controller;
public JsonResult DropDownChange(string dropdownValue)
// This action method gets called via an ajax request
{
if (dropdownValue != null && Request.IsAjaxRequest() == true)
{
paymentApplicationRefund =
cPaymentRepository.PayableEntity(dropdownValue);
paymentApplicationRefund.Address1.Trim();
paymentApplicationRefund.Address2.Trim();
paymentApplicationRefund.Name.Trim();
paymentApplicationRefund.City.Trim();
paymentApplicationRefund.Contact.Trim();
paymentApplicationRefund.State.Trim();
paymentApplicationRefund.Zip.Trim();
return Json(paymentApplicationRefund,"application/json");
}
else
{
return null;
}
}

View 3 Replies

Silverlight Or Jquery Ajax For Complex Data Form?

Oct 7, 2010

So part of my web app centers around this very important form which is used to create a form. Its like google docs form. The user keys in a type (checkbox, textfield, numericfield) and a label and slaps it into the system, and it generates a form somewhere.

Its a little more complex than google forms, the field types are complex and theres a lot more to that form (It happens to be a form generator for a finance plan)

The app is asp.net, I was thinking of using jquery and jquery's own ajax methods to post the data, but I think it would just turn into a very hairy situation, I then thought silverlight, but Ive never done silverlight before but I am an experienced .net guy.

So what do you guys think, will silverlight be too tough for a first timer for this kinda thing? Or should I stick to jquery. Plus points for silverlight is its an inhouse lan app and this particular page will be used by people with very high bandwidth.

Also I'm on .net 4 btw.

View 1 Replies

Passing Complex Objects To Javascript Via IScriptControl?

Mar 24, 2010

I'm playing around with a asp.net page that's using the IScriptControl interface to pass data from the code-behind to the custom javascript object running on the browser.I'm passing a number of properties via IScriptControl.GetScriptDescriptors(), and they're all working fine, except for one.That one is a class derived from System.Collections.Generic.Dictionary<>. And even that one has been working for me, so long as the elements in the collection were scalars - ints, doubles, and strings. But when I tried to pass a member of a class, it showed up as a null object in the javascript. The class in question is marked [Serializable]. I changed it to a struct, and got the same behavior.It looks as if the serializer used in IScriptControl does a shallow copy.

View 2 Replies

ADO.NET :: Passing A Complex Model To A Create View So It Can Be Populated On The HTTP-Postback?

Oct 25, 2010

I have a somewhat complex model that I need to pass to a MVC 2 Create view so its properties can be filled out. I'm not sure how to actually create this model as it has some relationship data that must also be filled out during the creation process.My main model is a Game. Most of its properties are scalar. It contains a foreign key to Content, for the game reviews, and there's a many-to-many relationship between Games and Platforms - games can be on a variety of platforms (PS3, XBox 360, etc.), and each platform has a library of games.When I pass data to my Edit view, it's as simple as:

[Code]....

I'm unsure what to do in the case of Create as I'm not sure how to link the associated parts - Content and Platforms - to a Game object.

View 1 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

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

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

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

Accessing JSON Data From Page Using JQuery

Nov 19, 2010

I am trying to load the JSON data that I am getting from an aspx page into a drop down list that I have on another page but I am getting the following javascript error.

Microsoft JScript runtime error: 'SiteID' is null or not an object

The SiteID is not returning null though and I believe that is an object. The following is the code I am using to try and load the data into the drop down list:

$.getJSON('Test.aspx?DepotID=' + DepotID, function (sites) {

View 17 Replies

Capture Data From From Using Jquery / Ajax / Json?

Apr 10, 2010

i have few textbox on the form and when the user submit i want to capture the data and insert into db

here is what my code looks like

beforeSubmit: function(data)
{ // called just before the form is submitted
var item = $("[id$='item']");
var category = $("[id$='category']");
var record = $("[id$='record']");

[Code].....

View 2 Replies

JQuery :: Getting Data Out Of Objects In A JSON Response

Sep 4, 2010

I'm working on an MVC2 site that needs to update the values of a select list based on the value selected by a user in another list. This is the response I'm getting from my controller's JSON action:

[{"Selected":false,"Text":"Client1Group1","Value":null},{"Selected":false,"Text":"Client1Group2","Value":null}]

View 2 Replies







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