分页存储过程,ASP.NET MVC中的Linq分页
分页存储过程
Code
广告:http://www.cnyolee.com/(讲述有理的网站)
http://www.rsion.com/
在ASP.NET MVC中分页
public ActionResult CateList(string page)
{
//分页大小
int pageSize = 15;
//总页数
int recordCount = (int)Helper.DataControl.FactoryCommand("select count(0) from articles where",CommandType.Text).ExecuteScalar();
int pageCount = recordCount / pageSize + (recordCount % pageSize == 0 ? 0 : 1);
//当前页数
int currentPage = page == null ? 0 :Convert.ToInt32(page);
if (currentPage <1) currentPage = 1;
else if (currentPage > pageCount) currentPage = pageCount;
//分页信息
TempData["pagedInfo"] = "<a href=\"" + Request.Path + "?page=" + (currentPage == 1 ? 1 : currentPage - 1) +
"\">上一页</a> | <a href=\"" + Request.Path + "?page=" + (currentPage == pageCount ? pageCount : currentPage + 1) +
"\">下一页</a> <input type=\"text\" size=\"3\" id=\"tbpage\"> <a href=\"#\" onclick=\"location.href='" + Request.Path +
"?page='+tbpage.value;\">跳页</a> "+
"第" + (currentPage) + "页/共" + pageCount + "页 每页" + pageSize +
"条记录/共" + recordCount + "条!";
//计算要跳过的页
int skipCount =recordCount<=pageSize?0:pageSize * (currentPage -1);
IEnumerable<Models.Article> articles = Common.DataContext.Articles.Skip(skipCount).Take(pageSize).OrderByDescending(a=>a.AddDate);
//注意:要先使用Skip(int)后再使用Take(int)
return View(articles);
}
{
//分页大小
int pageSize = 15;
//总页数
int recordCount = (int)Helper.DataControl.FactoryCommand("select count(0) from articles where",CommandType.Text).ExecuteScalar();
int pageCount = recordCount / pageSize + (recordCount % pageSize == 0 ? 0 : 1);
//当前页数
int currentPage = page == null ? 0 :Convert.ToInt32(page);
if (currentPage <1) currentPage = 1;
else if (currentPage > pageCount) currentPage = pageCount;
//分页信息
TempData["pagedInfo"] = "<a href=\"" + Request.Path + "?page=" + (currentPage == 1 ? 1 : currentPage - 1) +
"\">上一页</a> | <a href=\"" + Request.Path + "?page=" + (currentPage == pageCount ? pageCount : currentPage + 1) +
"\">下一页</a> <input type=\"text\" size=\"3\" id=\"tbpage\"> <a href=\"#\" onclick=\"location.href='" + Request.Path +
"?page='+tbpage.value;\">跳页</a> "+
"第" + (currentPage) + "页/共" + pageCount + "页 每页" + pageSize +
"条记录/共" + recordCount + "条!";
//计算要跳过的页
int skipCount =recordCount<=pageSize?0:pageSize * (currentPage -1);
IEnumerable<Models.Article> articles = Common.DataContext.Articles.Skip(skipCount).Take(pageSize).OrderByDescending(a=>a.AddDate);
//注意:要先使用Skip(int)后再使用Take(int)
return View(articles);
}
原创内容请您保留出处及地址 , 主页:展益