I have a list of menu items which can be sorted. I have the sort working which is based on this link.
However, I'm not sure how to save the order of the menu items to the database? I'm using nhibernate.
View Code
<h3>Sort Main Menus</h3>
<% using(Html.BeginForm()) { %>
<p>You can drag the items into a different order</p>
<p></p>
<div id="items">
<% foreach (var mainMenusList in ViewData.Model)
{%>
<%Html.RenderPartial("MainMenuEditor", mainMenusList, new ViewDataDictionary(ViewData) { { "mainMenuName", "mainMenu" } });%>
<%}
%>
</div>
<input type="submit" value="Save changes" />
<% } %>
<script type="text/javascript">
$(function()
{
$("#items").sortable({ axis: "y" });
});
</script>
MainMenuEditor Code
<div>
<input type="hidden" name="<%= ViewData["mainMenuName"] + ".index" %>" value="<%= ViewData.Model.Id %>" />
<% var fieldPrefix = string.Format("{0}[{1}].", ViewData["mainMenuName"], ViewData.Model.Id); %>
<%= Html.Hidden(fieldPrefix + "MainMenuID", ViewData.Model.Id) %>
<%= Html.TextBox(fieldPrefix + "Name", ViewData.Model.MainMenuName, new { size = "30"})%></div>