从$。员额传递数组到行动 [英] Passing Array to Action from a $.post
问题描述
我无法通过我的阵列通过.post的$
I am having trouble passing my array via a $.post.
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为空。任何想法?
The action sees privilegeIDs as null. Any ideas?
推荐答案
您需要设置 jQuery.ajaxSettings.traditional = TRUE;
为你的jQuery AJAX的设置。在jQuery的1.4,他们改变项目在表单POST序列化的方式。
You need to set jQuery.ajaxSettings.traditional = true;
for you jQuery ajax setting. In jQuery 1.4 they changed the way items are serialized in a form post.
请参阅:
http://forum.jquery.com/topic/nested-param-serialization
和:
<一href=\"http://stackoverflow.com/questions/309115/how-can-i-post-an-array-of-string-to-asp-net-mvc-controller-without-a-form/2527206#2527206\">http://stackoverflow.com/questions/309115/how-can-i-post-an-array-of-string-to-asp-net-mvc-controller-without-a-form/2527206#2527206
这篇关于从$。员额传递数组到行动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!