本人写的一个分页Helper,支持普通分页(也就是,首页、上一页、下一页、末页等),综合分页(普通分页和数字分页的综合)。下面是分页效果:
分页代码:
PagerHelper.cs
代码 1 using System;
2 using System.
Collections.Generic;
3 using System.Collections.Specialized;
4 using System.Linq;
5 using System.Web;
6 using System.Text;
7 using System.Web.Mvc;
8 using System.Web.Routing;
9 using System.Data.Objects.DataClasses;
10 namespace System.Web.Mvc
11 {
12 public static class
PagerHelper
13 {
14 ///
15 /// 分页
16 ///
17 ///
18 /// 分页id
19 /// 当前页
20 /// 分页尺寸
21 /// 记录总数
22 /// 分页头标签属性
23 /// 分页样式
24 /// 分页模式
25 ///
26 public static string Pager(this HtmlHelper helper, string id, int
currentPageIndex, int pageSize, int recordCount, object htmlAttributes, string className,PageMode mode)
27 {
28 TagBuilder builder = new TagBuilder("table");
29 builder.IdAttributeDotReplacement = "_";
30 builder.GenerateId(id);
31 builder.AddCssClass(className);
32 builder.MergeAttributes(new RouteValueDictionary(htmlAttributes));
33 builder.InnerHtml = GetNormalPage(currentPageIndex, pageSize, recordCount,mode);
34 return builder.ToString();
35 }
36 ///
37 /// 分页
38 ///
39 ///
40 /// 分页id
41 /// 当前页
42 /// 分页尺寸
43 /// 记录总数
44 /// 分页样式
45 ///
46 public static string Pager(this HtmlHelper helper, string id, int currentPageIndex, int pageSize, int recordCount, string className)
47 {
48 return Pager(helper, id, currentPageIndex, pageSize, recordCount, null, className,PageMode.Normal);
49 }
50 ///
51 /// 分页
52 ///
53 ///
54 /// 分页id
55 /// 当前页
56 /// 分页尺寸
57 /// 记录总数
58 ///
59 public static string Pager(this HtmlHelper helper,string id,int currentPageIndex,int pageSize,int recordCount)
60 {
61 return Pager(helper, id, currentPageIndex, pageSize, recordCount,null);
62 }
63 ///
64 /// 分页
65 ///
66 ///
67 /// 分页id
68 /// 当前页
69 /// 分页尺寸
70 /// 记录总数
71 /// 分页模式
72 ///
73 public static string Pager(this HtmlHelper helper, string id, int currentPageIndex, int pageSize, int recordCount,PageMode mode)
74 {
75 return Pager(helper, id, currentPageIndex, pageSize, recordCount, null,mode);
76 }
77 ///
78 /// 分页
79 ///
80 ///
81 /// 分页id
82 /// 当前页
83 /// 分页尺寸
84 /// 记录总数
85 /// 分页样式
86 /// 分页模式
87 ///
88 public static string Pager(this HtmlHelper helper, string id, int currentPageIndex, int pageSize, int recordCount,string className, PageMode mode)
89 {
90 return Pager(helper, id, currentPageIndex, pageSize, recordCount, null,className,mode);
91 }
92 ///
93 ///
获取普通分页
94 ///
95 ///
96 ///
97 ///
98 ///
99 private static string GetNormalPage(int currentPageIndex, int pageSize, int recordCount,PageMode mode)
100 &n