Send list/array as parameter with jQuery getJson

前端 未结 4 1508
攒了一身酷
攒了一身酷 2020-12-13 10:06

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(functio         


        
4条回答
  •  有刺的猬
    2020-12-13 10:26

    Try setting the traditional flag:

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

    works fine with:

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

提交回复
热议问题