我在通过 $.post 传递数组时遇到问题。
Javascript
var privIDs = [1,2,4,5];
$.post("/Home/GrantPrivilegesToUser", { privilegeIDs: privIDs }, function (data) {
alert("Data Loaded: " + data.success);
});
行动
public ActionResult GrantPrivilegesToUser(int[] privilegeIDs)
{
return Json(new {success=true});
}
该操作将 privilegeIDs 视为 null。有什么想法吗?
最佳答案
您需要为您的 jQuery ajax 设置设置 jQuery.ajaxSettings.traditional = true;
。在 jQuery 1.4 中,他们改变了项目在表单发布中序列化的方式。
请看:
http://forum.jquery.com/topic/nested-param-serialization
并且: How can I post an array of string to ASP.NET MVC Controller without a form?
关于c# - 从 $.post 传递数组到 Action,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4025353/