如何使用 jQuery Ajax post 将元素数组发布到控制器操作。
这就是我正在尝试的方式,但我的控制器接收到一个空数组。
function dipatchAllocations() {
// unSelected is an array of items of type int.
if (unSelected.length == 0) {
alert("Please select a line item to be dispatched.");
return;
}
debugger;
$.ajax({
type: 'POST',
url: '/Batch/SetToDispatch',
data: '{ "allocationId[]" : "[' + unSelected + ']","batchId" : "' + @Model.Id + '" }',
contentType: "application/json; charset=utf-8",
traditional: true,
success: updateView,
error: errorInSubscribing
});
};
这是我的控制器
[HttpPost]
public ActionResult SetToDispatch(long[] allocationId,long batchId)
{
// Perform some action here
return View("_ReadyToDispatchItems",model);
}
有人可以告诉我我缺少什么。
谢谢