MVC Simple Paging (no refresh page not implemented)

Source: Internet
Author: User

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 ' >&laquo;</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 ' >&raquo;</ 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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.