I am trying to send a jquery sortable list of items to my MVC method for data processing. Currently I am trying to send it via the following code:
var data = {};
data.projectId = projectId;
data.publishedSectionIds = $('#section_list').sortable('toArray');
// Perform the ajax
$.ajax({ url: '/Project/Publish',
type: 'POST',
data: data,
success: function (result) {
alert(result.message);
}
});
The problem with this code is it makes the Post parameters look like this:
projectId=2&publishedSectionIds[]=1&publishedSectionIds[]=2
The issue with this (as can be seen by the solution to this question) is that MVC only seems to serialize into a List if the post parameters do NOT have brackets.
How can I serialize the javascript array so my action with a List<int>
parameter model binds correctly?
Edit: The action's signature looks like:
public ActionResult Publish(int projectId, List<int> publishedSectionIds)