簡體   English   中英

如何在不使用任何插件的情況下使用jquery在ASP.Net MVC3中拖放表行?

[英]How to drag and drop table row in ASP.Net MVC3 using jquery without using any plugin?

我在ASP.Net MVC3項目中使用數據表插件。 在這里,我必須實現行重新排序。 我使用“ jQuery.dataTables.rowReordering.js”插件來實現它。 對於ui,它的工作正常,但是無法調用服務器端功能。

<script type="text/javascript">
    $(document).ready(function () {
        $('#myDataTable').dataTable().rowReordering({sURL: "/AdminArea/UpdateOrder" });
    });
</script>

我的控制器代碼是

public ActionResult Index()
 {
   return View(db.AdminAreas.ToList());
 }

public void UpdateOrder(int id, int fromPosition, int toPosition, string direction)
{
}

視圖

<table id="myDataTable">
<thead>
    <tr>
        <th>
            OrderNo
        </th>        
        <th>
            SubArea
        </th>
        <th>
            Description
        </th>        

    </tr>
</thead>
 <tbody>
@{
    if (@ViewData["SubAreaForArea"] != null)
    {
        IEnumerable<GridDragAndDrop.Models.SubAreaForAdmin> subarea = ViewData["SubAreaForArea"] as IEnumerable<GridDragAndDrop.Models.SubAreaForAdmin>;

        foreach (var item in subarea)
        {
            <tr class="order">
                <td>
                    @Html.DisplayFor(modelItem =>item.OrderNo)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.SubArea)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Description)
                </td>
            </tr>
        }
    }
}
</tbody>
</table>

我找不到問題。 因此,請幫助我使用jquery實現行拖放。 此外,更新的訂單還將在數據庫中更新。

您應該將Updateorder函數更改為

public void UpdateOrder(int id, string fromPosition, string toPosition, string direction)

因為jQuery數據表以mime類型("text")實現AJAX功能

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM