如何在不使用任何插件的情况下使用jQuery对ASP.Net MVC3中的表行进行重新排序?

时间:2018-09-21 09:23:09

标签: c# jquery asp.net-mvc

I am using datatable plugin in my ASP.Net MVC3 project. Here I have to implement the row reordering. I used "jQuery.dataTables.rowReordering.js" plugin to implement it. For ui its working fine, but It failed to call server side function.

我在ASP.Net MVC3项目中使用数据表插件。在这里,我必须实现行重新排序。我使用“ jQuery.dataTables.rowReordering.js”插件来实现它。对于ui来说,它可以正常工作,但是无法调用服务器端功能。

我在ASP.Net MVC3项目中使用数据表插件。在这里,我必须实现行重新排序。我使用“ jQuery.dataTables.rowReordering.js”插件来实现它。对于ui来说,它可以正常工作,但是无法调用服务器端功能。

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

</script>

my controller code is   


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

        if( direction == "back" )
        {
            var movedCompanies = objEpisodeDL.GetAllSegmentsByEpisodeId( 2 )
                        .Where( c => ( toPosition <= c.DisplayOrder && c.DisplayOrder <= fromPosition ) )
                        .ToList();

            foreach( var company in movedCompanies )
            {
                company.DisplayOrder++;
            }
        }
        else
        {
            var movedCompanies = objEpisodeDL.GetAllSegmentsByEpisodeId( 2 )
                        .Where( c => ( fromPosition <= c.DisplayOrder && c.DisplayOrder <= toPosition ) )
                        .ToList();
            foreach( var company in movedCompanies )
            {
                company.DisplayOrder--;
            }
        }

        objEpisodeDL.GetAllSegmentsByEpisodeId( 2 ).First( c => c.Id == id ).DisplayOrder = toPosition;

    }

视图是-

<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>

0 个答案:

没有答案