mvc 4 中的服务器端分页

server side pagination in mvc 4

创建了 mvc 4 application.currently 在该应用程序中,我使用客户端分页加载了数千条记录。 我就是这样做的

  1. 使用 select 所有 Linq 查询我正在 selecting 中的所有重新编码 table
  2. 然后使用 jquery tablesorter 插件将所有这些分开 记录成 10 x 10 块,逐页显示这些结果

这是它的照片

由于这是一个庞大的数据集,因此 load.There 花费了太多时间,因为我决定使用服务器端分页来做到这一点。

但我不知道如何实现这一点,你能否建议我使用 jquery table 分类器(不使用 jquery 数据 table)

这是控制器class

 public ActionResult Index()
 {

       return View(db.table_name.ToList());

 }

这就是我使用 jquery table 分拣插件

的方式
<script type="text/javascript">
    $(function () {
        $("#table-hover")

            .tablesorter({

                widthFixed: true,
                serverSideSorting: false

            })

            .tablesorterPager({
                container: $("#pager"),
                size: $(".pagesize option:selected").val()
            });

    });
 </script>

我建议使用 Troy Goode 的 PagedList,您也可以自己手动执行此操作,但那将是重新发明轮子。

我建议使用skip() 和take() 函数进行分页。当您调用此函数时,传递 page-no 和 no-of Record。并计算记录开始并显示。 例如,您想要显示 2 页和 50 条记录,然后像这样进行 linq 查询

var items =contex.employee.skip(50).take(50);

你想显示 3 页和 50 条记录,然后像这样进行 linq 查询

var items =contex.employee.skip(100).take(50);