ASP.NET MVC ajax 提交列表到 Action
1. Action 的代码
[HttpPost] public ContentResult SaveData(List<ClsA> listA, List<ClsA> listB) { return Content(string.Format("{0},{1}", listA.Count, listB.Count)); }
2. 以 Json 的方式提交
$.ajax({ url: '@Url.Action("SaveData", "FulfillRequest")', type: 'POST', data: { "listA[0].Id": "1", "listA[0].Name": "Stone", "listB[0].Id": "2", "listB[0].Name": "LL"}, success: function (result) { alert(result); }, error: function (result) { alert(result); } });
3. 以字符串的方式提交
$.ajax({ url: '@Url.Action("SaveData", "FulfillRequest")', type: 'POST', data: "listA[0].Id=1&listA[0].Name=Stone&listB[0].Id=2&listB[0].Name=LL", success: function (result) { alert(result); }, error: function (result) { alert(result); } });