Ajax分页(MVC下)(附源码,前后台)

网上找的一个分页js,自己改了改。。

前台页面

@{
    ViewBag.Title = "Index";
}
<h1>分页方法封装</h1>
<script src="~/gc-ui/js/gc-js/gc-js/jq_print/jquery-1.4.4.min.js"></script>
<script src="~/gc-ui/Pager/js/ajax_hack_gc.js"></script>
<script src="~/gc-ui/Pager/js/jquery.simplePagination.js" charset="gbk"></script>
<script src="~/gc-ui/Pager/js/gc_pager.js"></script>
<link href="~/gc-ui/Pager/css/simplePagination.css" rel="stylesheet" />
<script>
    $(function () {
        //$("#gc")
        var arr = [];
        arr.push("id");
        $.yms_Pager_ajax("gc", "/home/data", arr);
    });
</script>
<center>
    <table id="gc">
        <thead>
            <tr>
                <td>序号</td>
                <td>姓名</td>
            </tr>
        </thead>
        <tbody></tbody>
    </table>
</center>

后台控制器代码(用的ef)

 public ActionResult Index()
        {
            return View();
        }
        public ActionResult Data(int pageIndex = 1, int pageSize = 3)
        {
            testEntities t = new testEntities();
            List<ddd> list = t.ddd.ToList();
            

            int zys/*总页数*/ = (list.Count + pageSize - 1) / pageSize;
            var show_data/*json数据*/ = new { data = list.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList(), count = zys };
            return Json(show_data, JsonRequestBehavior.AllowGet);
        }

 js文件我上传上来。。

http://files.cnblogs.com/files/gaocong/Pager.rar

使用上有问题请@我

原文地址:https://www.cnblogs.com/gaocong/p/4930258.html