public ActionResult Index(int page = 1,int pageSize = 20) { var idNumber = Request.Form["txtIdNumber"]; var applicantName = Request.Form["txtApplicantName"]; var startDate = Request.Form["txtStartDate"]; var endDate = Request.Form["txtEndDate"]; int pageIndex = page; //int recordCount = 0; //var list = bll.GetList(applicantName, idNumber, startDate, endDate, (pageIndex - 1) * pageSize, pageSize, ref recordCount); //ViewBag.QueryRecordList = list; var list = bll.GetList(applicantName, idNumber, startDate, endDate); IPagedList<QueryRecord> pagedList = list.ToPagedList(pageIndex, pageSize); return View(pagedList); }
shtml
@model PagedList.IPagedList<QueryRecord> @using PagedList.Mvc; @{ foreach (var item in Model) { var identify_type = item.IDENTIFY_TYPE.ToString(); if (item.IDENTIFY_TYPE.ToInt().Equals(0)) { identify_type = "个人"; } else if (item.IDENTIFY_TYPE.ToInt().Equals(100)) { identify_type = "企业"; } } } <div> 总记录 @Model.TotalItemCount 每页 @Model.PageSize 条记录,共 @Model.PageCount 页,当前第 @Model.PageNumber 页 @Html.PagedListPager(Model, page => Url.Action("Index", new { page })) @Html.PagedListPager(Model, page => Url.Action("Index", new { page, pageSize = 100 }), new PagedListRenderOptions { LinkToFirstPageFormat = "首页", LinkToNextPageFormat = "下一页", LinkToPreviousPageFormat = "上一页", LinkToLastPageFormat = "末页", MaximumPageNumbersToDisplay = 5, DisplayItemSliceAndTotal = false,/*从头到尾显示页码*/ UlElementClasses = new[] { "pagination" },/*为ul li a 元素添加链接,使用ContainerDivClasses = new[] { "pagination" }替换 UlElementClasses = new[] { "pagination"},也是相同的效果。也可以不要此行代码,因为Bootstrap4与3相比,ul的class名没有变化,li 元素和a 元素加了page-item和page-link的类名。*/ LiElementClasses = new[] { "page-item" }, //PageClasses = new[] { "page-link" } }) </div>