Click here to Skip to main content
15,888,733 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Javascript

function Show() {
debugger;
for (var i = 0; i < Multi.length; i++) {
var Fname = Multi[i].FiratName;
var Lname = Multi[i].LastName;
var Mno = Multi[i].Mobileno;
var Add = Multi[i].Add;
var City = Multi[i].City;
var Hobby = Multi[i].Hobby;
var Gander = Multi[i].Gander;
}
obj = {
"FiratName": Fname,
"LastName": Lname,
"Mobileno": Mno,
"Add": Add,
"City": City,
"Hobby": Hobby,
"Gander": Gander,
};
var json = JSON.stringify(Multi);
$.ajax({
type: "POST",
traditional : true,
data: JSON.stringify({person: Multi }),
cache: false,
url: "/ArrayUse/ShowData",
dataType: "json",
success: function (data) {

}
});





that time my value is null

What I have tried:

controller coding



public JsonResult ShowData(string[][] values)
{
return Json(values);
}
Posted
Comments
F-ES Sitecore 25-May-17 12:21pm    
Google how to pass a JSON object to a controller, there are lots of examples

http://webcognoscere.com/post/how-to-post-a-json-object-to-a-controller-action.aspx

You need to use an object in your controller that the JSON object can be mapped to. Additionally you are not passing an array of objects, you are create one object that has the values of the last item in your Multi array. Rather than looping through your Multi array and overwriting variables with the data (meaning that item 1 overrites 0, 2 overrwites 1 and so on leaving you with only the last item in the array) and then creating one object, you need to instead have an array and create one object per iteration of your loop and push that object onto the array.
David_Wimbley 25-May-17 13:21pm    
You need to include your controller code as the problem could be with your controller

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900