Passing a list of objects to an ActionResult MVC controller method using jQuery Ajax

possible duplicate Passing a list of objects to an MVC controller method using jQuery Ajax

but my question is when i miss

var things = [
  {employee:'test',effectiveDate:'',expirationDate:'' },
  { employee:'test',effectiveDate:'',expirationDate:'' }
];

$.ajax({
 contentType: 'application/json',
 type: "POST",
 url: "/MyController/CheckMethod",
 dataType: "json",
 data: JSON.stringify(things),
 async: false,
 success: function (data) {

for the controller method, which is [HTTPPOPST] JsonResult, then I get valuein myList<MYMODEL>

but when I take the controller method as 'ActionResult', then I get nullinList<MYMODEL>

why is there something wrong?

+4
source share
3 answers

, JSON . , JSON.stringfy.

data: {"things" : things},

public IActionResult ActionName(List<Model> things)
+1

ajax. ,

public ActionResult CheckMethod(List<MYMODEL> items)

data: JSON.stringify('items': things),

data: JSON.stringify(things),
+3

, JsonResult - ActionResult (. ).

JSON, JsonResult; , Visual Studio , . ActionResult, .

, ; , List<MYMODEL>, "" , . , , AJAX, , ActionResult ( JsonResult).

+2

All Articles