Note that there are some explanatory texts on larger screens.

plurals
  1. POSaving JQuery Sortable (new order) to ASP.Net MVC controller?
    text
    copied!<p>I've implemented JQuery sortable, and it works fine. The problem is I can't pass the list in its new order to a controller so i can save it.</p> <pre><code>&lt;script type="text/javascript"&gt; $(document).ready(function() { $("#sortable").sortable({ axis: "y" }); }); $(function() { $("#submit-list").button(); $("#submit-list").click(function() { debugger; $.ajax({ url: '/Admin/SortedLists/', data: { items: $("#sortable").sortable('toArray') }, type: 'post', traditional: true }); }); }); &lt;/script&gt; &lt;h2&gt;Edit Roles&lt;/h2&gt; &lt;div&gt; &lt;ul id="sortable"&gt; &lt;% foreach (var item in Model.Roles) { %&gt; &lt;li&gt; &lt;%=Html.AttributeEncode(item.Name)%&gt; &lt;/li&gt; &lt;% } %&gt; &lt;/ul&gt; &lt;input type="submit" value="Save" id="submit-list"/&gt; &lt;/div&gt; </code></pre> <p>and my controller:</p> <pre><code>[HttpPost] public EmptyResult SortedLists(List&lt;string&gt; items) { return new EmptyResult(); } </code></pre> <p>List items comes back with the corrent number of elements - except each item are empty strings. </p> <p>If the original list looks like this</p> <ol> <li>1 - Car</li> <li>2 - Boat</li> <li>3 - Motorcycle</li> <li>4 - Plane</li> </ol> <p>And the user drags and resorts to be</p> <ol> <li>4 - Plane</li> <li>1 - Car</li> <li>3 - Motorcycle</li> <li>2 - Boat</li> </ol> <p>How can i pass that new order? I suppose id pass the whole thing on submit, delete the entire list and resubmit this whole list</p> <p>unless theres a better way? Taking advantage of Linq (using Linq to SQL) where i can insert the new order on everychange and do a submit changes?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload