发送列表/数组使用jQuery的getJSON参数 [英] Send list/array as parameter with jQuery getJson

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

问题描述

我在哪里,我要发送列表中的以下/阵列控制器的MVC方式:

I have the following where I'm trying to send list/array to MVC controller method:

var id = [];
var inStock = [];

$table.find('tbody>tr').each(function() {
    id.push($(this).find('.id').text());
    inStock.push($(this).find('.stocked').attr('checked'));
});

var params = {};
params.ids = id;
params.stocked = inStock; 

$.getJSON('MyApp/UpdateStockList', params, function() {
    alert('finished');
});    

在我的位指示:

public JsonResult UpdateStockList(int[] ids, bool[] stocked) { }

两者PARAMATERS为空。

both paramaters are null.

请注意,如果我改变PARAMS到单品

Note that if I change the params to single items

params.ids = 1;
params.stocked = true; 

public JsonResult UpdateStockList(int ids, bool stocked) { }

然后它工作正常,所以我不认为这是一个路由的问题。

then it works ok, so I don't think it's a routing issue.

推荐答案

尝试设置了传统的标记:

$.ajax({
    url: '/home/UpdateStockList',
    data: { ids: [1, 2, 3], stocked: [true, false] },
    traditional: true,
    success: function(result) {
        alert(result.status);
    }
});

工作正常:

public ActionResult UpdateStockList(int[] ids, bool[] stocked)
{
    return Json(new { status = "OK" }, JsonRequestBehavior.AllowGet);
}

这篇关于发送列表/数组使用jQuery的getJSON参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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