zoukankan      html  css  js  c++  java
  • 分页存储过程,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 + "页&nbsp;每页" + 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);
            }
  • 相关阅读:
    ElasticSearch学习记录
    用java代码手动控制kafkaconsumer偏移量
    kafka0.9.0及0.10.0配置属性
    kafka常用命令
    kafka消费者客户端(0.9.0.1API)
    kafka入门教程链接
    编程内功
    bzoj3145:[Feyat cup 1.5]Str
    3 SpringBoot与微服务
    2 微服务存在的问题和解决方案
  • 原文地址:https://www.cnblogs.com/newmin/p/1531836.html
Copyright © 2011-2022 走看看