2 qq 24026717 qq_24026717 于 2016.09.18 15:45 提问

psot 传递数组参数失败

这是前端的代码:
var projectlist = ["1","2","3"];
var url = "<%=Url.Action("GetPrjectData","Home") %>";
var data = { "prjectIdlist": projectlist };
$.post(url, data, function (response) {
if (response.data != "error") {
console.log(response) ;
}
});

后端:
[HttpPost]
public ActionResult GetPrjectData()
{
var projectArray = Request["prjectIdlist"];
if (projectArray == null)
return Json(new {data = "error"});

        return Json(new
        {
            data = list
        });
    }

前端我看过了,有值,但是到了后端就取不到了。

1个回答

showbo
showbo   Ds   Rxr 2016.09.18 17:00

jQuery.ajaxSettings.traditional=true;//禁止深度递归,要不得到的是键值对是prjectIdlist[]=1&prjectIdlist[]=2...而不是prjectIdlist=1&prjectIdlist=2
$.post(url, data, function (response) {.........

Csdn user default icon
上传中...
上传图片
插入图片