I am trying to get ajax sort version. I have this Javascript:
<script src="/Scripts/jquery-ui/jquery.ui.widget.js" type="text/javascript"></script>
<script src="/Scripts/jquery-ui/jquery.ui.mouse.js" type="text/javascript"></script>
<script src="/Scripts/jquery-ui/jquery.ui.sortable.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#sortThis").sortable({
handle: '.handle',
update: function () {
var order = $('#sortthis').sortable('serialize');
$.post(
"/find/ajaxactionhere",
order,
function (data) {
$("#info").html(data);
}
);
}
});
});
</script>
And this html in my asp.net mpc view:
<table>
<thead>
<tr>
<th>headers</th>
<th>headers</th>
</tr>
</thead>
<tbody id="sortThis">
<% foreach (var item in Model) %>
<% { %>
<tr id="list_<%: item.Tier %>">
<td>
<img class="handle" src="/sortIcon.gif" />
</td>
<td><%: item.data %></td>
</tr>
<% } %>
</tbody>
</table>
This allows me to reorder all the rows in the table. My action for processing an ajax send request is as follows:
[HttpPost]
public string ajaxactionhere(FormCollection form)
{
StringBuilder sb = new StringBuilder();
sb.Append(":: ");
if (form != null)
{
foreach (var key in form.AllKeys)
{
sb.Append(form[key]);
}
}
else
{
sb.Append("null");
}
return sb.ToString();
}
orderassigned to javascript variable $('#sortthis').sortable('serialize');. Whenever I show order, it says "[Object Object]". I cannot figure out how to get the contents of this object as a string.
Any help would be greatly appreciated.
source
share