我有以下要我发送列表/数组到MVC控制器方法:
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) { }
两个参数都为空。
请注意,如果我将参数更改为单个项目
params.ids = 1; params.stocked = true; public JsonResult UpdateStockList(int ids,bool stocked) { }
那么它可以正常工作,所以我不认为这是一个路由问题。
解决方法
尝试设置传统旗帜:
$.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); }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。