using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using SportsStore.WebUI.Models; using System.Text; namespace SportsStore.WebUI.HtmlHelpers { /// <summary> /// 分页辅助器 /// </summary> public static class PagingHelpers { public static MvcHtmlString PageLinks(this HtmlHelper html, PagingInfo pagingInfo, Func<int, string> pageUrl) { //需要使用可变字符串,引用System.Text StringBuilder sb = new StringBuilder(); for (int i = 1; i < pagingInfo.TotalPages; i++) { TagBuilder tag = new TagBuilder("a"); //构建一个<a>标签 tag.MergeAttribute("href", pageUrl(i)); tag.InnerHtml = i.ToString(); //AddCssClass向标记的Css添加样式 if (i == pagingInfo.CurrentPage) tag.AddCssClass("selected"); sb.Append(tag.ToString()); } return MvcHtmlString.Create(sb.ToString()); } } }
原文地址:https://www.cnblogs.com/chaonuanxi/p/10146908.html
时间: 2024-10-29 19:11:42