这个是用的插件分页技术
前台引用和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" /> <script type="text/javascript"> 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; } }); });
</script>
//Html代码
<div style="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()); }