Pagination HTML helper method
usingSystem.Text;usingsystem.web;usingSYSTEM.WEB.MVC;namespacesystem.web.mvc{ Public Static classhtmlextensions {#regionPagination HTML helper method/// <summary> ///Pagination HTML helper method/// </summary> /// <param name= "HtmlHelper" ></param> /// <param name= "CurrentPage" ></param> /// <param name= "pageSize" ></param> /// <param name= "TotalCount" ></param> /// <param name= "parameterstring" ></param> /// <returns></returns> Public StaticHtmlstring Pagenavigate ( ThisHtmlHelper HtmlHelper,intCurrentPage,intPageSize,intTotalCount,stringparameterstring) { varRedirectto =HtmlHelper.ViewContext.RequestContext.HttpContext.Request.Url.AbsolutePath; PageSize= PageSize = =0?3: pageSize; varTotalPages = Math.max ((totalcount + pageSize-1)/PageSize,1);//Total Pages varOutput =NewStringBuilder (); Output. Append ("<nav>"); Output. Append ("<ul class= ' pagination ' >"); stringPagesizrwithparameter =string. Empty; if(!string. IsNullOrEmpty (parameterstring)) Pagesizrwithparameter= PageSize +"&"+parameterstring; if(totalpages>1) {output. AppendFormat ("<li><a href= ' {0}?pageindex=1&pagesize={1} ' aria-label= ' Previous ' ><span aria-hidden= ' true ' >«</span></a></li>", Redirectto,pagesizrwithparameter); if(CurrentPage >1)//Process Previous page connectionOutput. AppendFormat ("<li><a href= ' {0}?pageindex={1}&pagesize={2} ' > Previous </a></li>", redirectto,currentpage-1, Pagesizrwithparameter); Output. Append (""); intCurrint =5; for(inti =0; I <Ten; i++) {//A total of 10 page numbers, front five five if((Currentpage+i-currint) >=1&& (currentpage+1-currint) <=totalpages) { if(Currint = = i)//Current page ProcessingOutput. AppendFormat ("<li class= ' active ' ><a href= ' {0}?pageindex={1}&pagesize={2} ' >{3}</a></li>", Redirectto, CurrentPage, Pagesizrwithparameter, currentpage); Else//General page HandlingOutput. AppendFormat ("<li><a href= ' {0}?pageindex={1}&pagesize={2} ' >{3}</a></li>", redirectto,currentpage+i-currint,pagesizrwithparameter,currentpage+i-currint); } output. Append (""); } if(CurrentPage < TotalPages)//process Next Page connectionOutput. AppendFormat ("<li><a href= ' {0}?pageindex={1}&pagesize={2} ' > Next </a></li>", Redirectto, CurrentPage +1, Pagesizrwithparameter); Output. Append (""); if(CurrentPage! =totalpages) output. AppendFormat ("<li><a href= ' {0}?pageindex={1}&pagesize={2} ' ><span aria-hidden= ' true ' >»</ Span></a></li>", Redirectto, TotalPages, Pagesizrwithparameter); Output. Append (""); } output. Append ("</ul>"); Output. Append ("</nav>"); return Newhtmlstring (output. ToString ()); } #endregion }}
Page Related location call
<!--the viewdata,totalrecord stored in the controller represents the number of bars returned based on the data added to the query, parameter represents the search criteria (keyword search, and so on)-@Html. Pagenavigate ( int. Parse (viewdata["pageIndex"). ToString ()),int. Parse (viewdata["pageSize"). ToString ()),int. Parse (viewdata["totalrecord"). ToString ()), viewdata["parameter"]. ToString ())
Implementation of Controller-related methods
Example: PublicAction Moment (intpageindex=1,intPagesize= -){intTotalrecord =0; List<Aniuge_Moments> Lam =momentsbussiness.getinstance (). Getmoment (Pagesize,pageindex, outTotalrecord);//get a list of paginated displaysviewdata["Totalrecord"]=Totalrecord; viewdata["PageIndex"]=PageIndex; viewdata["pageSize"]=pageSize;#regionGenerate Search state hold dataStringBuilder SB=NewStringBuilder ();foreach(stringIteminchRequest.QueryString.Allkeys) {if(!item. Equals ("PageIndex") &&!item. Equls ("pageSize") ) sb. Append (Item+"="+request.querystring[item]+"&");} viewdata["parameter"]=SB. Tostring (). Trim ("&");#endregionreturnView (LAM);}
To have no refresh paging and more features see "Lightweight Form Plugin bootstrap table." Powerful support for fixed header, single/check, sort, paging, search, and custom table first-class features. "This essay
MVC Simple Paging (no refresh page not implemented)