I have tried to get an example but was noy successful so far. I have created various arrays and filled them in jquery. How to post all of them to the controller? 开发者_如何学C On the controller side how to retrieve them and their values? I would appreciate if I can have an example or a link with much explanation since i`m completely new to using ajax post and mvc.
What if I have other arrays as well to post over to the controller?
function test()
{ var stringArray = new Array(); stringArray[0] = "item1"; stringArray[1] = "item2"; stringArray[2] = "item3"; var postData = { values: stringArray };
$.post("/Home/SaveList",
postData,
function(data){
alert(data.Result);
}, "json");
}
Here's one way to pass a two dimensional string array (array of array of strings) to a controller action:
[HttpPost]
public ActionResult Arrays(string[][] arrays)
{
// Do something with the arrays
return Json(new { status = "success" });
}
and to post:
var arrays = [{'0':'value1', '1':'value2'},
{'0':'value3', '1':'value4'},
{'0':'value5', '1':'value6'}];
$.post('/home/arrays', { arrays: arrays }, function(result) {
alert(result.status);
});
精彩评论