asp.net - Sending data to controller by Ajax -
usually send data controller ajax following::
$.ajax({ type: "post", contenttype: "application/json; charset=utf-8", url: "/controller/myaction", data: "{'name':'" + id + "','class':'" + cls + "'}", datatype: "json",
see have members send controller 2 different parameters. want send list.
but want send list controller in 1 parameter. possible how can achieve that?
json.stringify
key here.
here code:
var mylist = { list: [{ name: "a", class: "b" }, { name: "c", class: "d" }] }; $.ajax({ type: 'post', url: '/{controller}/{action}', cache: false, data: json.stringify(mylist), datatype: 'json', contenttype: 'application/json; charset=utf-8' });
Comments
Post a Comment