【asp.net mvc】 扩展 htmlhelper 实现分页
2017-04-11 11:12
966 查看
参考文档:http://www.cnblogs.com/caofangsheng/p/5670071.html
http://www.cnblogs.com/artech/archive/2012/03/13/code-binding.html
http://www.cnblogs.com/xqaizx/p/5565447.html
【asp.net core】 扩展 TagHelper 分页 : http://www.cnblogs.com/wangrudong003/p/5705744.html
自定义分页类
分页信息类
PageInfo
修改 Views 文件夹下 web.config,新增命名空间
在页面调用方式
http://www.cnblogs.com/artech/archive/2012/03/13/code-binding.html
http://www.cnblogs.com/xqaizx/p/5565447.html
【asp.net core】 扩展 TagHelper 分页 : http://www.cnblogs.com/wangrudong003/p/5705744.html
自定义分页类
using BooksStore.WebUI.Models; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Web; using System.Web.Mvc; namespace BooksStore.WebUI.HtmlHelpers { public static class PagingHelper { /// <summary> /// 创建分页html /// </summary> /// <param name="helper"></param> /// <param name="pagingInfo"></param> /// <param name="func"></param> /// <returns></returns> public static MvcHtmlString PageLinks(this HtmlHelper helper, PageInfo pagingInfo, Func<int, string> func) { var sb = new StringBuilder(); for (var i = 1; i <= pagingInfo.TotalPages; i++) { //创建 <a> 标签 var tagBuilder = new TagBuilder("a"); //添加特性 tagBuilder.MergeAttribute("href", func(i)); //添加值 tagBuilder.InnerHtml = i.ToString(); if (i == pagingInfo.PageIndex) { tagBuilder.AddCssClass("selected"); } sb.Append(tagBuilder); } return MvcHtmlString.Create(sb.ToString()); } } }
分页信息类
using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace BooksStore.WebUI.Models { public class PageInfo { /// <summary> /// 总数 /// </summary> public int TotalItems { get; set; } /// <summary> /// 页容量 /// </summary> public int PageSize { get; set; } /// <summary> /// 当前页 /// </summary> public int PageIndex { get; set; } /// <summary> /// 总页数 /// </summary> public int TotalPages => (int)Math.Ceiling((decimal)TotalItems / PageSize); } }
PageInfo
修改 Views 文件夹下 web.config,新增命名空间
在页面调用方式
@Html.PageLinks(Model, x => Url.Action("Index", new { pageIndex = x , category = Model.CurrentCategory }))
相关文章推荐
- asp.net mvc 分页控件:HtmlHelper扩展
- ASP.NET MVC 使用总结(二)——扩展HtmlHelper实现动态生成title及meta
- 新版asp.net mvc 分页控件:HtmlHelper扩展
- ASP.NET MVC HtmlHelper 自定义扩展分页功能
- ASP.NET MVC 使用总结(二)——扩展HtmlHelper实现动态生成title及meta
- asp.net mvc htmlhelper扩展
- [转]ASP.NET MVC HtmlHelper扩展之Calendar日期时间选择
- dhl: 在 ASP.NET MVC 中创建自定义 HtmlHelper 使用扩展方法创建 HTML Helper
- [ASP.NET MVC]通过对HtmlHelper扩展简化“列表控件”的绑定
- Asp.net MVC Preview 4 中自定义Jquery的HtmlHelper扩展
- asp.net MVC添加HtmlHelper扩展示例和用法
- Asp.net MVC Preview 4 中自定义Jquery的HtmlHelper扩展
- ASP.Net MVC开发基础学习笔记:二、HtmlHelper与扩展方法
- asp.net mvc 中 htmlhelper 中各生成 html 控件函数的实现(表达式解析)
- ASP.NET MVC HtmlHelper扩展之Calendar日期时间选择
- ASP.NET MVC DropDownList扩展,实现foreach@Html.DropDownListFor(p=>p.Type,p.Type,TypeItem)
- asp.net mvc htmlhelper 扩展方法
- [ASP.NET MVC]为HtmlHelper添加一个RadioButtonList扩展方法
- ASP.NET MVC DropDownList扩展,实现foreach@Html.DropDownListFor(p=>p.Type,p.Type,TypeItem)
- [ASP.NET MVC]为HtmlHelper添加一个RadioButtonList扩展方法