如何使用ASP.NET MVC中的jQuery ajax方法将数据列表发送到Controller Action方法?

这是我的Action Mehtod

public JsonResult GetById(IEnumerable idList) { //..... } 

还有我的JavaScript。 我正在使用li元素的id属性创建一个字符串数组

 var idArr = []; var list = $("#ulApplications li"); $.each(list, function () { idArr.push($(this).attr("id")) }); $.ajax( { type: "GET", url: "/rolemanagement/application/GetById/", contentType: false, datatype: "json", data: { 'idList': idArr }, success:........ 

在我的Action方法中,我没有得到任何数据。我好像错过了什么。 谢谢

将你的ajax改为

 $.ajax({ type: "GET", url: "/rolemanagement/application/GetById", // should use '@Url.Action(..)' dataType: 'json', contentType: "application/json; charset=utf-8", data: JSON.stringify({ idList: idArr }), // stringify success: .... }) 

我尝试了下面的代码似乎工作正常,

 $.ajax({ type: "GET", url: "@Url.Action("GetById", new { area = "rolemanagement", controller = "application"})", data: { idList: [{ a: 'a' }, { a: 'b' }] }, dataType: "json", contentType: "application/json; charset=utf-8", success: function (data) { console.log(data); }, error: function () { throw new Error("Error occurred."); } }); 

@stephen已经给出了甚至stringify甚至不需要发送数据。

在stackoverflow和其他博客上搜索之后。 我找到了一个适合我的解决方案,虽然上面给出的答案非常正确,但它们对我没有用。 这是我的答案

 var IdList = {idList:idArr} $.ajax( { type: "GET", url: "/rolemanagement/application/GetById/", contentType: false, datatype: "json", data: IdList, traditional: true, success: function (data) { alert(data); },