jQuery Sortable .toArray with ASP.NET MVC ActionResult
- by Stacey
Third try at fixing this tonight - trying a different approach than before now.
Given a jQuery Sortable List..
<ul id="sortable1" class="connectedSortable">
<li class="ui-state-default" id="item1">Item 1</li>
<li class="ui-state-default" id="item2">Item 2</li>
<li class="ui-state-default">Item 3</li>
<li class="ui-state-default ">Item 4</li>
<li class="ui-state-default">Item 5</li>
</ul>
<ul id="sortable2" class="connectedSortable">
</ul>
And ASP.NET MVC ActionResult..
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Insert( string[] items )
{
return null;
}
Activated by JavaScript...
$("#sortable1, #sortable2").sortable({
connectWith: '.connectedSortable',
dropOnEmpty: true,
receive: function () {
var items = $(this).sortable('toArray');
alert(items);
$.ajax({
url: '/Manage/Events/Insert',
type: 'post',
data: { 'items': items }
});
}
}).disableSelection();
The 'alert' DOES show the right items. It shows 'item1, item2' etc. But my ASP.NET MVC ActionResult gets nothing. The method DOES fire, but the 'items' parameter comes in null. Any ideas?