MVCPage帮助类
控制器代码
public ActionResult Article(int? page) { //Session["ArticleClass"] = context.ArticleClass.ToList(); PagerInfo info = new PagerInfo(); info.RecordCount = context.Article.ToList().Count();//条目总数 info.PageSize = 10;//每页条目数 info.CurrentPageIndex = (page != null ? (int)page : 1);//当前页 List<Article> list = context.Article.OrderBy(a => a.Id).Skip((info.CurrentPageIndex - 1) * info.PageSize).Take(info.PageSize).ToList(); PagerQuery<PagerInfo, IEnumerable<Article>> data = new PagerQuery<PagerInfo, IEnumerable<Article>>(info, list); return View(data); }
前台页面代码
需要先对PageQuery集合的引用 <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<PagerQuery<PagerInfo,IEnumerable<PostCounterManage.Models.Article>>>" %> foreach (var item in Model.EntityList) <%= Html.Pager("pager", Model.Pager.CurrentPageIndex, Model.Pager.PageSize, Model.Pager.RecordCount,"pages", PageMode.Numeric)%>
原文地址:http://www.cnblogs.com/JackFeng/archive/2010/01/25/JackFeng.html