如何使用jQuery Ajax發佈數據元素到控制器操作。使用ajax post發佈數組到MVC3控制器
這是我如何嘗試,但我的控制器收到一個空數組。
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);
}
有人能不能指點我,我錯過了什麼。
感謝
有你累刪除 「[]」 allocationId – ankur
後才能顯示'unSelected'聲明? – testCoder