How can I post an array of elements to a controller action using jQuery Ajax post.
This is how I am trying, but my controller recieving a null array.
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
});
};
And this is my controller
[HttpPost]
public ActionResult SetToDispatch(long[] allocationId,long batchId)
{
// Perform some action here
return View("_ReadyToDispatchItems",model);
}
Can somebody advice me what I am missing.
Thanks
unSelecteddeclaration?