• MVC 分页


    后台代码:

    using Webdiyer.WebControls.Mvc;

     1 public ActionResult Index(int id = 1)
     2         {
     3             int pageIndex = id;
     4             int count;
     5             int pageSize = 7;
     6 
     7             List<News> newsList =
     8                 newsSer.QueryByPage(pageIndex, pageSize, out count, c => c.IsDel == false && c.Status == (int)Enums.EStatus.pass, c => c.PTime)
     9                     .ToList();
    10 
    11             ViewBag.count = Math.Ceiling(count * 1.0 / pageSize);
    12             ViewBag.pageIndex = pageIndex;
    13             ViewBag.newsList = newsList;
    14 
    15             PagedList<News> mPage = newsList.ToPagedList(pageIndex, pageSize);
    16             mPage.TotalItemCount = count;
    17             mPage.CurrentPageIndex = pageIndex;//此处3行可换为 IPagedList<News> mPage=new PagedList<News>(newsList,pageIndex,pageSize,count);
    18 
    19             ViewBag.mPage = mPage;
    20             return View();
    21         }

    前台代码:

    @using Webdiyer.WebControls.Mvc
    @{
        Layout = null;
        List<News> newsList2 = ViewBag.newsList;
        PagedList<News> mPage = ViewBag.mPage;
    }
    
     @Html.Pager(mPage, new PagerOptions { PageIndexParameterName = "id", CurrentPagerItemTemplate = "<span class="current">{0}</span>", DisabledPagerItemTemplate = "<span class="disabled">{0}</span>", Id = "diggpager" })

    样式:

     1 /*分页 楚晓冰*/
     2 /* digg style*/
     3 /* 蓝色:#000099 */
     4 /* 淡蓝色:rgb(0, 160, 234) */
     5 
     6 div#diggpager { padding-right: 3px; padding-left: 3px; padding-bottom: 3px; margin: 3px; padding-top: 3px; text-align: center; margin-top: 25px; }
     7 div#diggpager a { border-right: #aaaadd 1px solid; padding-right: 5px; border-top: #aaaadd 1px solid; padding-left: 5px; padding-bottom: 2px; margin: 2px; border-left: #aaaadd 1px solid; color: rgb(0, 160, 234); padding-top: 2px; border-bottom: #aaaadd 1px solid; text-decoration: none; }
     8 div#diggpager a:hover { border-right: rgb(0, 160, 234) 1px solid; border-top: rgb(0, 160, 234) 1px solid; border-left: rgb(0, 160, 234) 1px solid; color: #000; border-bottom: rgb(0, 160, 234) 1px solid; }
     9 div#diggpager a:active { border-right: rgb(0, 160, 234) 1px solid; border-top: rgb(0, 160, 234) 1px solid; border-left: rgb(0, 160, 234) 1px solid; color: #000; border-bottom: rgb(0, 160, 234) 1px solid; }
    10 div#diggpager span.current { border-right: rgb(0, 160, 234) 1px solid; padding-right: 5px; border-top: rgb(0, 160, 234) 1px solid; padding-left: 5px; font-weight: bold; padding-bottom: 2px; margin: 2px; border-left: rgb(0, 160, 234) 1px solid; color: #fff; padding-top: 2px; border-bottom: rgb(0, 160, 234) 1px solid; background-color: rgb(0, 160, 234); float: none !important; }
    11 div#diggpager span.disabled { border-right: #eee 1px solid; padding-right: 5px; border-top: #eee 1px solid; padding-left: 5px; padding-bottom: 2px; margin: 2px; border-left: #eee 1px solid; color: #ddd; padding-top: 2px; border-bottom: #eee 1px solid; }

    前台代码2:

    @Html.Pager(mPage, new PagerOptions { PageIndexParameterName = "id", NumericPagerItemCount = 5, ContainerTagName = "ul", CssClass = "pagination", CurrentPagerItemTemplate = "<li class="active"><a href="#">{0}</a></li>", DisabledPagerItemTemplate = "<li class="disabled"><a>{0}</a></li>", PagerItemTemplate = "<li>{0}</li>", Id = "bootstrappager2", PageIndexBoxId = "pageIndexBox", GoToButtonId = "goToBtn" })

    样式用的是 bootstrap.css

    备注:参考文档 http://www.webdiyer.com/mvcpager/demos/applycss/

  • 相关阅读:
    创建web应用程序时出现 SharePoint HRESULT:0x80070094 问题
    用Javascript获取SharePoint当前登录用户的用户名及Group信息
    javascript连接数据库
    sharepoint 中banner 图片的放大
    GridView导出Excel 类库
    SQL Server 性能调优
    GridView长字段的显示
    MOSS母版页制作学习笔记(二)
    sharepoint 中批量导入导出
    JavaScript 动态更改sharepoint 列表的颜色
  • 原文地址:https://www.cnblogs.com/ICE_Inspire/p/5162417.html
Copyright © 2020-2023  润新知