实例懒得做切几个图把代码发上要用的自己搞啦~ 下面是一个helper类 Code namespace SystemWebMvc { public enum BarStyle { yahoo digg meneame flickr sabrosus scott quotes black black grayr yellow jogger starcraft tres megas technorati youtube msdn badoo viciao yahoo green_black } public static class PagerBarExtension { public static string RenderPagerBar(this HtmlHelper html int page int total) { return RenderPagerBar(html page total BarStyletechnorati); } public static string RenderPagerBar(this HtmlHelper html int page int total BarStyle style) { return RenderPagerBar(html page total style total); } public static string RenderPagerBar(this HtmlHelper html int page int total BarStyle style int show) { if (total == ) { return ; } else { StringBuilder sb = new StringBuilder(); string _path = htmlViewContextHttpContextRequestPath; sbAppend(<div class=\); sbAppend(styleToString()); sbAppend(\ >); string queryString = htmlViewContextHttpContextRequestQueryStringToString(); if (queryStringIndexOf(page=) < ) { queryString += &page= + page; } Regex re = new Regex(@page=\d+ RegexOptionsIgnoreCase); string result = reReplace(queryString page={}); if (page != ) { sbAppendFormat(<span><a href=\{}\ title=\第一页\>{}</a></span> _path + ? + stringFormat(result ) <<); sbAppendFormat(<span><a href=\{}\ title=\上一页\>{}</a></span> _path + ? + stringFormat(result page ) <); } if(page>(show+)) { sbAppendFormat(<span><a href=\{}\ title=\前 + (show + ) + 页\>{}</a></span> _path + ? + stringFormat(resultpage(show + )) ); } for (int i = pageshow; i <= page+show; i++) { if (i == page) { sbAppendFormat(<span class=\current\>{}</span> i); } else { if (i > & i<=total) { sbAppendFormat(<span><a href=\{}\>{}</a></span> _path + ? + stringFormat(result i) i); } } } if (page < (total(show))) { sbAppendFormat(<span><a href=\{}\ title=\后 + (show + ) + 页\>{}</a></span> _path + ? + stringFormat(result page + (show + )) ); } if (page < total) { sbAppendFormat(<span><a href=\{}\ title=\下一页\>{}</a></span> _path + ? + stringFormat(result page + ) >); sbAppendFormat(<span><a href=\{}\ title=\最后一页\>{}</a></span> _path + ? + stringFormat(result total) >>); } sbAppendFormat(<span class=\current\>共{}页</span> page total); sbAppend(</div>); return sbToString(); } } } } 使用(VIEW) Code <%@ Page Language=C# MasterPageFile=~/Views/Shared/SiteMaster Inherits=SystemWebMvcViewPage %> <asp:Content ID=indexHead ContentPlaceHolderID=head runat=server> <title>Home Page</title> <link rel=stylesheet type=text/css /> </asp:Content> <asp:Content ID=indexContent ContentPlaceHolderID=MainContent runat=server> <%= HtmlActionLink(带其它参数Indexnew {s = MVC} )%> <%= HtmlActionLink(带其它参数Indexnew { cid = } )%> <%= HtmlActionLink(带其它参 数Indexnew {s = MVC cid = } )%> <%= HtmlRenderPagerBar(ConvertToInt(ViewData[Page])ConvertToInt(ViewData[Total]))%> <%= HtmlRenderPagerBar(ConvertToInt(ViewData[Page])ConvertToInt(ViewData[Total])BarStylebadoo )%> <%= HtmlRenderPagerBar(ConvertToInt(ViewData[Page])ConvertToInt(ViewData[Total])BarStylebadoo )%> <%= HtmlRenderPagerBar(ConvertToInt(ViewData[Page])ConvertToInt(ViewData[Total])BarStyleblack )%> <%= HtmlRenderPagerBar(ConvertToInt(ViewData[Page])ConvertToInt(ViewData[Total])BarStyledigg )%> <%= HtmlRenderPagerBar(ConvertToInt(ViewData[Page])ConvertToInt(ViewData[Total])BarStyleflickr )%> <%= HtmlRenderPagerBar(ConvertToInt(ViewData[Page])ConvertToInt(ViewData[Total])BarStylegrayr )%> </asp:Content> 最后一个int参数表示显示当前页左右各多少个页码 效果 public ActionResult Index(int? pagestring sint? cid) { int _page = page??; ViewData[Message] = Welcome to ASPNET MVC!; ViewData[Page] = _page; ViewData[Total] = ; return View(); } 不是啥高深的东西不过蛮实用 计算总页数和skip啥的就自己搞啦 |