码迷,mamicode.com
首页 > Web开发 > 详细

MVC 分页

时间:2016-01-27 12:18:55      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:

后台代码:

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;
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; }

 

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

 

MVC 分页

标签:

原文地址:http://www.cnblogs.com/DKnight/p/5162417.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!