PagedList
作者:互联网
在DAL内编辑分页代码
public List<information> Showinf(int pageindex,int pagesize,out int totalcount,out int totalpage) { IQueryable<information> list = db.informations; totalcount = list.Count();//总条数 totalpage = Convert.ToInt32(Math.Ceiling(totalcount * 1.0 / pagesize));//总页数 //分页语句 return list.OrderBy(m => m.Fid).Skip((pageindex - 1) * pagesize).Take(pagesize).ToList(); }
Controllers:
public ActionResult Showinfor( int pageindex = 1, int pagesize = 1) { int totalcount; int totalpage; var qusy = Dal.Showinf( pageindex, pagesize, out totalcount, out totalpage); var list = new StaticPagedList<information>(qusy, pageindex, pagesize, totalcount); return View(list); }
注意要引用:
using PagedList;
using PagedList.Mvc;
引用,管理NUGet程序包
下载PageList.Mvc控件程序包
注意需要下载两个程序包,第二个PageList程序包会自动下载
在需要分页的页面引用
@using WebApplication2.Models
@using PagedList;
@using PagedList.Mvc;
@model StaticPagedList<information>
然后直接编写正常的视图页面
最后编写分页翻页控件
@Html.PagedListPager(Model, pageindex=>Url.Action("Showinfor",new { pageindex, Cid=Request["Cid"], Did=Request["Did"], }))
标签:pageindex,pagesize,int,totalcount,using,PagedList 来源: https://www.cnblogs.com/JMFK/p/15022497.html