从$。员额传递数组到行动 [英] Passing Array to Action from a $.post

查看:104
本文介绍了从$。员额传递数组到行动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法通过我的阵列通过.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆