提交阵列参数使用jQuery AJAX /负载 [英] Submit array param with jQuery ajax/load

查看:141
本文介绍了提交阵列参数使用jQuery AJAX /负载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

公众的ActionResult DoSomething的(字符串[]改编,布尔someBool,诠释someInt){}

试图从jQuery的调用上述方法:

trying to call the above method from jQuery:

var test = [];
test.push('dog');
test.push('cat');

$container.load('MyController/DoSomething',
                { 'arr[]': test, 'someBool': true, 'someInt': 1 },
                function(response, status, xhr) {
                    // ...
                });

数组paramater为空,其他PARAMS的罚款。我在做什么错了?

the array paramater is null, other params are fine. What am I doing wrong?

Chrome开发者工具显示表单数据被提交为

Chrome developer tools shows form data being submitted as

arr%5B%5D%5B%5D:dog
arr%5B%5D%5B%5D:cat
someBool:true
someInt:1

不知道怎么回事,但有不正确的看向我。

not sure whats going on there but doesn't look right to me

推荐答案

如果您正在使用jQuery 1.4你可能需要设置 传统的 参数真正,以便在ASP.NET MVC默认模型联格式兼容

If you are using jquery 1.4 you might need to set the traditional parameter to true in order to be compatible with the default model binder format in ASP.NET MVC:

var test = [];
test.push('dog');
test.push('cat');

$.ajax({
    url: 'MyController/DoSomething',
    type: 'GET',
    traditional: true,
    data: { arr: test, someBool: true, someInt: 1 },
    success: function(result) {
        $container.html(result);
    }
});

或者如果你preFER的 .load() 方法:

var data = { arr: test, someBool: true, someInt: 1 };
$container.load('MyController/DoSomething', $.param(data, true), 
    function(response, status, xhr) {
    // ...
});

这篇关于提交阵列参数使用jQuery AJAX /负载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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