基于mvcpager的分页(get请求,刷新页面),提供两种样式(来自bootstrap的样式)
使用方法:
先把mvcpager.dll引用加入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 | 前台: @{ Layout = null; } @using Webdiyer.WebControls.Mvc @model PagedList< string > <! DOCTYPE html> < html > < head > < meta name="viewport" content="width=device-width" /> < title >Index</ title > < link href="~/Content/css_pager.css" rel="stylesheet" /> </ head > < body > < div > @foreach (var item in Model) { @item< br /> } </ div > < div style="text-align:center;"> @Html.Pager(Model, new PagerOptions { PageIndexParameterName = "pageIndex", ContainerTagName = "ul", PrevPageText = "上页", NextPageText = "下页", FirstPageText = "首页", LastPageText = "尾页", CssClass = "pagination", PagerItemsSeperator = "", CurrentPagerItemWrapperFormatString = "< li class=\"active\">< a href=\"#\">{0}</ a ></ li >", PagerItemWrapperFormatString = "< li >{0}</ li >" }, new { id = "bootstrappager", @class = "pagination" }) <!-- @class 可为pagination或pager 样式可自行修改样式表--> </ div > </ body > </ html > |
后台代码
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using Webdiyer.WebControls.Mvc; namespace MvcApplication6.Controllers { public class HomeController : Controller { // // GET: /Home/ public ActionResult Index(int pageIndex=1, int pageSize=2) { List<string> list = new List<string>(){ "a", "b", "c", "d" }; return View(list.ToPagedList(pageIndex, pageSize)); } } }
1 | @Html.Pager(Model, new PagerOptions { PageIndexParameterName = "pageIndex", ContainerTagName = "ul", PrevPageText = "上页", NextPageText = "下页", FirstPageText = "首页", LastPageText = "尾页", CssClass = "pagination", PagerItemsSeperator = "", CurrentPagerItemWrapperFormatString = "< li class=\"active\">< a href=\"#\">{0}</ a ></ li >", PagerItemWrapperFormatString = "< li >{0}</ li >" }, new { id = "bootstrappager", @class = "pagination" }) |
样式更改:class为pager或pagination
如图:
下载路径: https://files.cnblogs.com/files/gaocong/MvcPager.rar
样式文件:
.pagination { border-radius: 4px; display: inline-block; margin: 20px 0; padding-left: 0; } .pagination > li { display: inline; } .pagination > li > a, .pagination > li > span { background-color: #fff; border: 1px solid #ddd; color: #337ab7; float: left; line-height: 1.42857; margin-left: -1px; padding: 6px 12px; position: relative; text-decoration: none; } .pagination > li:first-child > a, .pagination > li:first-child > span { border-bottom-left-radius: 4px; border-top-left-radius: 4px; margin-left: 0; } .pagination > li:last-child > a, .pagination > li:last-child > span { border-bottom-right-radius: 4px; border-top-right-radius: 4px; } .pagination > li > a:hover, .pagination > li > span:hover, .pagination > li > a:focus, .pagination > li > span:focus { background-color: #eee; border-color: #ddd; color: #23527c; z-index: 3; } .pagination > .active > a, .pagination > .active > span, .pagination > .active > a:hover, .pagination > .active > span:hover, .pagination > .active > a:focus, .pagination > .active > span:focus { background-color: #337ab7; border-color: #337ab7; color: #fff; cursor: default; z-index: 2; } .pagination > .disabled > span, .pagination > .disabled > span:hover, .pagination > .disabled > span:focus, .pagination > .disabled > a, .pagination > .disabled > a:hover, .pagination > .disabled > a:focus { background-color: #fff; border-color: #ddd; color: #777; cursor: not-allowed; } /*.pagination-lg > li > a, .pagination-lg > li > span { font-size: 18px; line-height: 1.33333; padding: 10px 16px; } .pagination-lg > li:first-child > a, .pagination-lg > li:first-child > span { border-bottom-left-radius: 6px; border-top-left-radius: 6px; } .pagination-lg > li:last-child > a, .pagination-lg > li:last-child > span { border-bottom-right-radius: 6px; border-top-right-radius: 6px; } .pagination-sm > li > a, .pagination-sm > li > span { font-size: 12px; line-height: 1.5; padding: 5px 10px; } .pagination-sm > li:first-child > a, .pagination-sm > li:first-child > span { border-bottom-left-radius: 3px; border-top-left-radius: 3px; } .pagination-sm > li:last-child > a, .pagination-sm > li:last-child > span { border-bottom-right-radius: 3px; border-top-right-radius: 3px; }*/ .pager { list-style: outside none none; margin: 20px 0; padding-left: 0; text-align: center; } .pager li { display: inline; } .pager li > a, .pager li > span { background-color: #fff; border: 1px solid #ddd; border-radius: 15px; display: inline-block; padding: 5px 14px; text-decoration: none; } .pager li > a:hover, .pager li > a:focus { background-color: #eee; text-decoration: none; } .pager .next > a, .pager .next > span { float: right; } .pager .previous > a, .pager .previous > span { float: left; } .pager .disabled > a, .pager .disabled > a:hover, .pager .disabled > a:focus, .pager .disabled > span { background-color: #fff; color: #777; cursor: not-allowed; } .pager > .active > a, .pager > .active > span, .pager > .active > a:hover, .pager > .active > span:hover, .pager > .active > a:focus, .pager > .active > span:focus { background-color: #eee; cursor: default; z-index: 2; }
分类:
C#
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· winform 绘制太阳,地球,月球 运作规律
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人