TDa*_*ver 8 arrays ajax jquery json asp.net-mvc-3
我在JS中有一个字符串数组.所有成员实际上都是数字.
我的控制器有一个int []参数.
我从jquery发送它:
$.ajax({url: someUrl, data: {ids : JSON.stringify(id_array) }, ...)
Run Code Online (Sandbox Code Playgroud)
我用它来收到它
public ActionResult MyAction(int[] ids) { ...
Run Code Online (Sandbox Code Playgroud)
参数没有被填充,我已经检查过,Request.Form["ids"]包含" [\"25\",\"26\"]",JSON数组的字符串表示.有没有办法在没有大量的int解析的情况下自动执行此操作?
Kei*_*amo 11
您是否尝试过不对数组进行字符串化并让mvc的默认模型绑定发挥作用
$.ajax({url: someUrl, data: {ids : id_array }, ...)
Run Code Online (Sandbox Code Playgroud)
我很确定.net MVC会看到数组并看到它是一个int数组并正确映射到你的数组
Llo*_*oyd 11
对于MVC3,您需要配置jQuery以使用传统的"浅层"序列化.请参见此处.
客户端AJAX请求:
jQuery.ajaxSettings.traditional = true; //enable "shallow" serialisation globally
$.get("someUrl", {ids : id_array });
Run Code Online (Sandbox Code Playgroud)
行动方法:
public ActionResult MyAction(string[] ids) { ... }
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9182 次 |
| 最近记录: |