我在ASP.NET MVC5项目中使用来自jQueryUI(Sortable plugin)的Sortable插件。一切正常,但是如何在更改内容后保存在SERVER端(带动作:“保存”按钮)表在这张桌子上?例外:在行中编辑,删除或创建新项目。
这是我的代码:
<table class="table table-bordered table-striped table-condensed table-hover smart-form has-tickbox">
<thead>
<tr>
<th>Number</th>
<th>Step</th>
<th>Edit</th>
</tr>
</thead>
<tbody id="sortable" >
@{
foreach (var item in Model.vKrokyReseni)
{
<td>@item.poradi</td>
<td class="editable">@item.popis</td>
<td><input type="button" value="Delete" /></td>
</tr>
}
}
</tbody>
</table> '
这是我的jQuery脚本:
<script>
$(function () {
$("#sortable").sortable({
placeholder: "ui-state-highlight"
});
$("#sortable").disableSelection();
});
答案 0 :(得分:0)
您可以在表行中设置自定义属性,如下所示:
<table id="myTable">
<tbody>
<tr data-id="1">
<td>1</td>
<td>Blah Blah Blah Blah</td>
</tr>
<tr data-id="2">
<td>2</td>
<td>2222 22222 22222 2222 22222</td>
</tr>
<tr data-id="3">
<td>3</td>
<td>Test Test Test Test Test</td>
</tr>
<tr data-id="4">
<td>4</td>
<td>4444 4444 4444 4444 4444</td>
</tr>
<tr data-id="5">
<td>5</td>
<td>Hi Hi Hi Hi Hi Hi</td>
</tr>
<tr data-id="6">
<td>6</td>
<td>Bye Bye Bye Bye Bye Bye Bye</td>
</tr>
</tbody>
</table>
并包含保存更改的功能:
$("#saveBtn").click(function(){
$("#myTable tr").each(function(index){
console.log("original position: " +$(this).attr("data-position") + " New position: " + (index+1));
//save your new order
})
});
答案 1 :(得分:0)
解决了!在我发布到Controller
之后,我通过更改行来输入"<td><input type="input" value="@name"></td>"
来解决它