In an AJAX request on a server in MVC, how can I pass the id list to a controller function?
I accept with or without HTML helpers.
I know that the MVC middleware has no problem when it comes to simple types like int , string and bool .
Is it something like what I should use and massage instead in action?
I don't care if I need to use array or List , and even if the strings I int or strings , I can always convert them. I just need them on the server. My List List is now null.
JavaScript:
var ids= [1,4,5];
MVC action:
public ActionResult ShowComputerPackageBuffer(List<int> ids)
EDIT: Added my AJAX request
$(document).ready(function () { $('#spanComputerPackagesBuffer').on('click', function () { var ids = $('#divComputerPackagesBuffer').data('buffer'); console.log('bufferIds: ' + bufferIds); var data = { ids: ids }; var url = getUrlShowComputerPackageBuffer(); loadTable(url, "result", data); }); });
SOLUTIONS: // Thanks to @aherrick's comment. I missed the good old "traditional"
$.ajax({ type: "POST", url: '@Url.Action("ShowComputerPackageBuffer", "Buffer")', dataType: "json", traditional: true, data: { bufferIds: bufferIds } });
source share