I want to use jqueryui sortable to reorder columns in a table by dragging and dropping, however I don't know how to even return the data to the POST action, let alone loop through it.
I am generating my <ul>
like so:
<ul id="sort">
@foreach (var item in Model)
{
<li id="id_@Html.DisplayFor(modelItem => item.Id)">@Html.DisplayFor(modelItem => item.Title)</li>
}
</ul>
This is the sortable js code:
$('#sort').sortable({
update: function () {
var ids = $('#sort').sortable('serialize');
var url = "/admin/cms/ReorderPages";
$.post(url, ids, function (data) {
$("#msg").html(data);
});
console.log(ids);
}
});
And my POST method:
[HttpPost]
public string ReorderPages(string ids)
{
return ids;
}
Upon dragging and dropping I get the following console logged:
id[]=1&id[]=4&id[]=2&id[]=3&id[]=14
So that part works, but how do I get that into my POST action and loop through it to get the ids?