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

时间: 2024-07-30 10:12:42

MVC 分页的相关文章

C# MVC分页,razor

IMVCPages interface IMVCPages { int GetItemsCount(); int GetPageSize(); int GetPagesCount(); /// <summary> /// 当前页面索引,用于分页 /// </summary> int CurrentPageIndex { get; set; } } View <div> 查询到 @Model.GetItemsCount() 条记录,共 @Model.GetPagesCou

MVC 分页获取数据 及点选按钮

@model PagedList<Lyxm.Entity.Suggestion>@using Webdiyer.WebControls.Mvc <div>    <ul class="breadcrumb">        <li>            @Html.ActionLink("基础维护", "", "")            <span class=&quo

PagedList.MVC分页

? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86

转:MVC分页

原文地址:http://www.cnblogs.com/iamlilinfeng/p/4075292.html 分页总是搞得我很烦,也是因为刚接触,貌似有好多插件,之前在用一个,可是后来发现一翻页原来的筛选项就提交不上了,然后就换了这个,其实这篇文章对我而言最起作用的还是View文件中BeginForm中的参数 new RouteValueDictionary { { "id", "" } },也许原来的分页方式加上这个参数也是可以的,还没尝试. 前言 前几天在博客

Mvc分页组件MvcSimplePager代码重构

1 Mvc分页组件MvcSimplePager代码重构 1.1 Intro 1.2 MvcSimplePager 代码优化 1.3 MvcSimplePager 使用 1.4 End Mvc分页组件MvcSimplePager代码重构 Intro MvcSimplePager 是为解决分页的而做的一个通用.扩展性良好的轻量级分页扩展,可以自定义分页时调用的方法,自定义分页所用的样式,样式与代码分离,维护方便. 网上有许多分页都是查询所有数据再从中查询某一页的数据,但是个人感觉数据很少时还可以,如

Mvc 分页栏扩展方法

using System; using System.Collections.Generic; using System.Reflection; using System.Text; using System.Web.Mvc; namespace System.Web.Mvc {     #region Mvc 分页栏扩展方法 HtmlPaginationBar /// <summary>     ///  Mvc 分页栏扩展方法     /// </summary>     pu

ASP.NET MVC 分页MvcPager

ASP.NET MVC 分页MvcPager 开源框架  admin  8个月前 (08-20)  1484浏览 他连续12年获得微软MPV称号,几年前,他写的ASP.NET分页控件,被很多.NET开发人员使用,现在他又写了名为MvcPager的分页扩展,并免费开源,支持MVC通用分页,与EF完美结合,支持AJAX分页,简单灵活,提供多个演示案例,是迄今为止最好的MVC分页方式,推荐各位ASP.NET MVC开发者使用. 分页是每个项目必须面对的技术点,不好的分页不但体验不好,而且会影响系统的整

Asp.NET MVC X.PageList.MVC 分页详解以及自定义样式

最近在研究MVC,自己做了个小项目:其中用到了分页功能,在网上找了很多相关的第三方插件,最后选择了X.PageList.MVC,插件是开源的,有利于学习所以选择了它,这并不是说其它的分页插件不好,只是个人爱好,当然,用于以后还是会说好的.^^ 首先可以看下源,在GitHub上,地址如下: X.PageList.MVC GitHub 源代码地址 初步看了一个项目比较精简,核心部分为X.PagedList.Mvc中的内容,配置文件为:PagedListRenderOptions.cs 这个插件可以完

Asp.Net MVC 分页、检索、排序整体实现

原文:Asp.Net MVC 分页.检索.排序整体实现 很多时候需要这样的功能,对表格进行分页.排序和检索.这个有很多实现的方式,有现成的表格控件.用前端的mvvm,用户控件.但很多时候看着很漂亮的东西你想进一步控制的时候却不那么如意.这里自己实现一次,功能不是高大全,但求一个清楚明白,也欢迎园友拍砖.前端是bootstrap3+jPaginate,后台基于membership.没什么难点. 先上效果图. 分页其实就是处理好 每页项目数.总项目数.总页数.当前页.为了方便复用,就先从仓库开始说起

MVC分页,从无到有

题外话:前段时间逛博客园,偶然看到一个大神写的帖子:上层人员决定底层人员所用的技术,来论述了一下为什么java工资会大致比.net高,没办法因为这两个技术就像两个帝国一样,以至于平常的互撕完全是站在利益的角度上,没办法!他说如果.net的管理人员多了,那么.net所用的人也就多了,为此,又让我想到了开源的分享的真正意义:为了自己的技术,为了阐述自己写完这个项目的兴奋,同时每一个开源,也会让属于这个技术的人多一点提升.这就不是1+1=2那么简单了:理想的状态就是,高层管理人员越多,开源分享的越多,