MVC使用x.PagedList分页
MVC分页
1.Install Package
Tools=> NuGet Package Manager=>Manager NuGet Packages of Solution
安装 X.PagedList和X.PagedList.MVC
package.config文件: <package id="X.PagedList" version="1.24.1.300" targetFramework="net45" />
<package id="X.PagedList.Mvc" version="4.9.1.310" targetFramework="net45" />
View界面:
@model PagedList.IPagedList<T>
@using PagedList
@using PagedList.Mvc
@Html.PagedListPager(Model, page => Url.Action("ActionName", new { page }))
//分页控件
controller:
public ActionResult ActionName(int? page)
{
int PageNumber=page?? 1;//page为null时默认值为1
int PageSize=10;
return View(list.ToPagedList(PageNumber,PageSize));
}