我已經實現了JQuery sortable,它工作正常。問題是我無法將其新順序的列表傳遞給控制器,因此我可以保存它。能夠保存JQuery Sortable(新訂單)到ASP.Net MVC控制器嗎?
如果原始表看起來是 1 - 餅乾 2 - chocalate 3 - 餅乾 4 - 糖果
而且用戶拖動和度假村是
1 - 巧克力 2 - 餅乾 3 - 糖果 4 - cookies
如何將新訂單傳遞給我的控制器以重新排序模型中的數據。
$('td, a', '#MenuItem').each(function() {
var cell = $(this);
cell.width(cell.width());
});
$(document).ready(function() {
$('#MenuItem tbody').sortable({
axis: 'y',
update: function (event, ui) {
var data = $(this).sortable('serialize');
// POST to server using $.post or $.ajax
$.ajax({
data: data,
type: 'POST',
url: 'MoveFunction'
});
}
});
});
[HttpPost]
public ActionResult MoveFunction(Product vm)
{
return View(vm);
}
public class Product
{
//ID's
[Key]
public int ProductID { get; set; }
//Members
<fieldset class="fieldset">
<legend class="legend">Products</legend>
<table id = "MenuItem" class="promo full-width alternate-rows" style="text-align: center;"> <!-- Cedric Kehi DEMO CHANGE -->
<tr>
<th>Product Code
</th>
<th>Product Template
</th>
@*<th>
@Html.DisplayNameFor(model => model.IndexList[0].Priority)
</th>
<th>
@Html.DisplayNameFor(model => model.IndexList[0].WindowProduct)
</th>*@
<th>Description <!-- JACK EDIT -->
</th>
<th>Actions</th>
</tr>
<tbody>
@foreach (var item in Model.IndexList)
{
<tr>
<td class="center-text">
@Html.DisplayFor(modelItem => item.ProductCode)
</td>
<td>
@Html.DisplayFor(modelItem => item.ProductTemplate.Description)
</td>
@*<td class="center-text">
@Html.DisplayFor(modelItem => item.Priority)
</td>
<td class="center-text">
@Html.Raw(item.WindowProduct ? "Yes" : "No")
</td>*@
<td>
@Html.DisplayFor(modelItem => item.Description)
</td>
<td class="center-text nowrap">
@Html.ActionLink(" ", "Edit", new { id = item.ProductID }, new { title = "Edit", @class = "anchor-icon-no-text edit" })
@Html.ActionLink(" ", "Details", new { id = item.ProductID }, new { title = "Details", @class = "anchor-icon-no-text details" })
@Html.ActionLink(" ", "Delete", new { id = item.ProductID }, new { title = "Delete", @class = "anchor-icon-no-text delete" })
</td>
</tr>
}
</tbody>
</table>
由於某種原因,它不會讓我更新代碼 – user5813072
你能證明你將如何解決這個問題 – user5813072
一個例子,我已經編輯我是新來的,爲什麼我已張貼這一問題在這裏有一些Ajax原因代碼 – user5813072