This example of this article for you to share the MVC pagination code for your reference, the details are as follows
Using System.Collections.Generic;
Using System.Collections.Specialized;
Using System.Linq;
Using System.Web;
Using System.Text;
Using SYSTEM.WEB.MVC;
Using System.Web.Routing;
Using System.Data.Objects.DataClasses; namespace SYSTEM.WEB.MVC {public static class Pagerhelper {///<summary>///paging///</summary>/// <param name= "helper" ></param>///<param name= "id" > Paging id</param>///"<param name=" currentpa Geindex "> Current page </param>///<param name=" pageSize "> Paging size </param>///<param name=" RecordCount "& gt; Total records </param>///<param name= "htmlattributes" > Page Header label properties </param>///<param name= "ClassName" > Pagination Styles </param>///<param name= "mode" > Paging mode </param>///<returns></returns> Public St Atic string Pager (This HtmlHelper helper, string id, int currentpageindex, int pageSize, int recordCount, Object Htmlattri Butes, String className, Pagemode mode) {Tagbuilder buIlder = new Tagbuilder ("table"); Builder.
Idattributedotreplacement = "_"; Builder.
Generateid (ID); Builder.
addCssClass (ClassName); Builder.
Mergeattributes (New RouteValueDictionary (htmlattributes)); Builder.
InnerHtml = Getnormalpage (CurrentPageIndex, pageSize, recordCount, mode); Return builder.
ToString (); ///<summary>///Paging///</summary>///<param name= "helper" ></param>///<param na Me= "id" > Pagination id</param>///<param name= "CurrentPageIndex" > Current page </param>///<param name= " PageSize "> Paging size </param>///<param name=" RecordCount "> Records total </param>///<param name=" ClassName "> Pagination styles </param>///<returns></returns> public static string Pager (this HtmlHelper helper, string ID, int currentpageindex, int pageSize, int recordCount, string className) {return Pager (helper, ID, Currentpageinde
X, pageSize, RecordCount, NULL, ClassName, pagemode.normal); }///<summary>///Paging///</summary>///<param name= "helper" ></param>///<param name= "IDs" > Points Page id</param>///<param name= "CurrentPageIndex" > Current page </param>///<param name= "pageSize" > Paging Size & lt;/param>///<param name= "RecordCount" > Total records </param>///<returns></returns> public Stat IC string Pager (This HtmlHelper helper, string id, int currentpageindex, int. pageSize, int recordCount) {return Pag
ER (helper, id, CurrentPageIndex, pageSize, recordCount, NULL); ///<summary>///Paging///</summary>///<param name= "helper" ></param>///<param N Ame= "id" > Pagination id</param>///<param name= "CurrentPageIndex" > Current page </param>///<param name= " PageSize "> Paging size </param>///<param name=" RecordCount "> Records total </param>///<param name=" mode "> Paging mode </param>///<returns></returns> public static string Pager (this HtMlhelper Helper, string id, int currentpageindex, int pageSize, int recordCount, Pagemode mode) {return Pager (helper
, IDs, CurrentPageIndex, pageSize, recordCount, null, mode); ///<summary>///Paging///</summary>///<param name= "helper" ></param>///<param na Me= "id" > Pagination id</param>///<param name= "CurrentPageIndex" > Current page </param>///<param name= " PageSize "> Paging size </param>///<param name=" RecordCount "> Records total </param>///<param name=" ClassName "> Pagination style </param>///<param name=" mode > Paging mode </param>///<returns></returns> public s Tatic string Pager (This HtmlHelper helper, string id, int currentpageindex, int pageSize, int recordCount, String Classnam
E, Pagemode mode) {return Pager (helper, id, CurrentPageIndex, pageSize, RecordCount, NULL, className, mode); }///<summary>///get normal pagination///</summary>///<param name= "CurrentPageIndex" ></param>///<param name= "pageSize" ></param>///<param name= "RecordCount" ></param> <returns></returns> private static string getnormalpage (int currentpageindex, int pageSize, int record Count, Pagemode mode) {int pagecount = (recordCount% PageSize = = 0? recordcount/pagesize:recordcount/pagesi
Ze + 1);
StringBuilder url = new StringBuilder (); Url.
Append (HttpContext.Current.Request.Url.AbsolutePath + "? Page={0}");
NameValueCollection collection = HttpContext.Current.Request.QueryString; String[] Keys = collection.
AllKeys; for (int i = 0; i < keys. Length; i++) {if (Keys[i]. ToLower ()!= the "page" URL.
AppendFormat ("&{0}={1}", Keys[i], collection[keys[i]);
StringBuilder sb = new StringBuilder (); Sb.
Append ("<tr><td>"); Sb.
AppendFormat ("total {0} records, total {1} pages, current {2} page", RecordCount, PageCount, CurrentPageIndex); if (CurrentPageIndex = = 1) sb. Append ("<span> home </span> "); else {string url1 = string. Format (URL.
ToString (), 1); Sb.
AppendFormat ("<span><a href={0}> home </a></span>", URL1); } if (CurrentPageIndex > 1) {string url1 = string. Format (URL.
ToString (), currentPageIndex-1); Sb.
AppendFormat ("<span><a href={0}> prev </a></span>", URL1); Else sb.
Append ("<span> prev </span>"); if (mode = = Pagemode.numeric) sb. Append (Getnumericpage (CurrentPageIndex, PageSize, RecordCount, PageCount, url.)
ToString ())); if (CurrentPageIndex < PageCount) {string url1 = string. Format (URL.
ToString (), CurrentPageIndex + 1); Sb.
AppendFormat ("<span><a href={0}> next Page </a></span>", URL1); Else sb.
Append ("<span> next page </span>"); if (CurrentPageIndex = = PageCount) sb.
Append ("<span> last </span>"); else {string url1 = string. Format (URL. ToString (), PagecoUNT); Sb.
AppendFormat ("<span><a href={0}> last </a></span>", URL1); Return SB.
ToString ();
///<summary>///Get digital paging///</summary>///<param name= "CurrentPageIndex" ></param> <param name= "PageSize" ></param>///<param name= "RecordCount" ></param>///<param Name = "PageCount" ></param>///<param name= "url" ></param>///<returns></returns> Privat e static string getnumericpage (int currentpageindex, int pageSize, int recordCount, int pagecount, string url) {int
K = CURRENTPAGEINDEX/10;
int m = currentpageindex% 10;
StringBuilder sb = new StringBuilder ();
if (CURRENTPAGEINDEX/10 = = PAGECOUNT/10) {if (M = = 0) {k--;
m = 10;
else m = pagecount% 10;
else M = 10; for (int i = k * ten + 1; I <= K * + M; i++) {if (i = = CurrentPageIndex) sb. AppendFormat ("<sPan><font color=red><b>{0}</b></font></span> ", i); else {string url1 = string. Format (URL.
ToString (), i); Sb.
AppendFormat ("<span><a href={0}>{1}</a></span>", URL1, I); } return SB.
ToString (); }///<summary>///paging mode///</summary> public enum Pagemode {///<summary>///normal paging mode//
/</summary> Normal,///<summary>///normal paging plus digital paging///</summary> Numeric}
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.