码迷,mamicode.com
首页 > Web开发 > 详细

MVC分页技术

时间:2015-09-15 01:32:53      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:

这个是用的插件分页技术

前台引用和js

    <script type="text/javascript" src="/js/jquery-1.10.2.min.js"></script>
    <script type="text/javascript" src="/js/kkpager.min.js"></script>
    <link rel="stylesheet" type="text/css" href="/css/kkpager_orange.css" />
  

function getParameter(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return unescape(r[2]); return null;
        }

        $(function () {var pageCount = $(‘#pageCount‘).val();//获取总页码
            var totalRecords = $(‘#totalRecords‘).val();//获取总条数
            var pageNo = getParameter(‘pno‘);
            if (!pageNo) {
                pageNo = 1;
            }
            //生成分页
            //有些参数是可选的,比如lang,若不传有默认值
            kkpager.generPageHtml({
                //当前页码
                pno: pageNo,
                //总页码
                total: pageCount,
                //总数据条数
                totalRecords: totalRecords,
                //链接前部
                hrefFormer: ‘/ProductQuality/ExpertProduct‘,
                //链接尾部
                hrefLatter: ‘‘,
                getLink: function (n) {
                    return this.hrefFormer+this.hrefLatter+‘?id=‘+@(Convert.ToInt32(INDID))+‘&pno=‘ + n;
                }

            });
});




//Html代码
 <div style="width:800px;margin:0 auto;">
                    <div id="kkpager"></div>
                </div>

mvc中

        public ActionResult ExpertProduct(string id,string pno)
        {
            int pageIndex;
            int pageSize=2;

            if (!int.TryParse(pno,out pageIndex))
            {
                pageIndex = 1;
            }
            id = id == null ? "0101" : id;//获取专家
            Dictionary<string, object> param = new Dictionary<string, object>();
            param.Add("ID", id);
            string inspectionUser = RouteManager.GetApiRoute("ProductQuality", "GetInspectionExpert", param); ;
            IList<InspectionUsers> model = JsonConvert.DeserializeObject<List<InspectionUsers>>(Catalogs.GetCatalogs(inspectionUser));this.ViewBag.pageCount = Math.Ceiling((double)model.Count/pageSize);//获取总页码
this.ViewBag.totalRecords = model.Count;//总条数
return View(model.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList()); }

 

 

 

http://files.cnblogs.com/files/xbblogs/uploadify.zip

MVC分页技术

标签:

原文地址:http://www.cnblogs.com/xbblogs/p/4808950.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!