int pageIndex;
int pageSize = 9;
if(!int.TryParse(Request["pageIndex"],out pageIndex))
{
pageIndex = 1;
}
mvcDbEntities db = new mvcDbEntities();
//总页数
int totalCount = db.YongHu.Count();
int pageCount = Convert.ToInt32(Math.Ceiling(totalCount * 1.0 / pageSize));
if (pageIndex < 1)
{
pageIndex = 1;
}
if(pageIndex>pageCount)
{
pageIndex = pageCount;
}
var yonghuList = db.YongHu.Where<YongHu>(c => true).OrderBy<YongHu, int>(c => c.YongHuId).Skip<YongHu>((pageIndex - 1) * pageSize).Take<YongHu>(pageSize);
List<YongHu> list = yonghuList.ToList();
ViewData.Model = list;
ViewBag.PageIndex = pageIndex;
ViewBag.PageSize = pageSize;
ViewBag.PageCount = pageCount;
ViewBag.TotalCount = totalCount;
return View();
<%for(int i=1;i<=(int)ViewBag.PageCount;i++){ %>
<%:Html.ActionLink(i.ToString(),"Index",new {pageIndex=i}) %>
<%} %>
<%:Html.ShowPageNavigate((int)ViewBag.PageIndex,(int)ViewBag.PageSize,(int)ViewBag.TotalCount) %>
添加一个样式表