效果图:
控制器代码:
**public ActionResult Index(int pageIndex=1,int pageSize=2)
{
using (EnRoleEntities db=new EnRoleEntities())
{
var books = db.Books.ToList();
var res = db.Books
.OrderBy(p=>p.ID)
.Skip((pageIndex-1)*pageSize)
.Take(pageSize)
.ToList();
ViewBag.pageIndex = pageIndex;
ViewBag.pageSize = pageSize;
//计算总数
ViewBag.totalRows = books.Count;
//计算共有多少页
ViewBag.totalPage = Math.Ceiling(books.Count * 1.0 / pageSize);
return View(res);
}
}**
视图代码: