PublicActionResult Mycomment (stringIdintpage =1) { stringUserID =EndUserLoginManage.Instance.loginUserID; ICOMMENTINFOBLL C_BLL=NewCOMMENTINFOBLL (); intAllcount =0; intpageindex = (Page <1?1: page); intPageSize =Ten; List<CommentInfo> commentlist = C_bll. Getlistbyuserid (UserID, outAllcount, pageindex, pagesize); if(Commentlist! =NULL&& Commentlist.count >0) {COMMENTMESSAGEBLL UCMB=NewCOMMENTMESSAGEBLL (); foreach(varIteminchcommentlist) {Item. URL="/estate/detail/"+item. ProjectID; //item.commentmessagelist = ucmb. Getlistbyparentid (item. ID);}} Viewbag.userid=userid; Viewbag.commentlist= Commentlist;//List of commentsViewbag.pageindex =pageindex; Viewbag.pagesize=pagesize; Viewbag.allcount=Allcount; returnView (); }@{Viewbag.title="my comments"; Layout="~/views/shared/_personallayoutpage.cshtml"; stringUserID =Viewbag.userid; List<CommentInfo> commentlist = viewbag.commentlist asList<commentinfo>; intpage =Viewbag.pageindex; intPageSize =viewbag.pagesize; intAllcount =Viewbag.allcount; intPageCount = Allcount/pagesize; if(allcount% pagesize! =0) {PageCount + =1; } intPrepage = (page = =1?1: Page-1); intnextpage = (page = = PageCount? Pagecount:page +1); intCountbegin, Countend; Datahelper.getpagehelper (page, PageCount,6, outCountbegin, outcountend); } #regionPage number calculation function/// <summary> ///page number calculation function/// </summary> /// <param name= "Curpage" >Current page number</param> /// <param name= "Allpage" >All pages</param> /// <param name= "Pagelength" >How many page numbers to display</param> /// <param name= "Countbegin" >Result: Start Page number (including itself)</param> /// <param name= "Countend" >Result: End page number (including itself)</param> Public Static voidGetpagehelper (intCurpage,intAllpage,intPagelength, out intCountbegin, out intcountend) { intHalfpage = (Pagelength-1) /2; intMoD = (Pagelength-1) %2; Countbegin= Curpage-Halfpage; Countend= curpage + Halfpage +MoD; if(Countbegin <1) {countend = Countend + (1-Countbegin); Countbegin =1; } if(Countend > Allpage) {Countbegin = Countbegin-(countend-allpage); countend =Allpage;} Countbegin= Countbegin <1?1: Countbegin; Countend= countend > Allpage?Allpage:countend; } #endregion<divclass="GRZX_SC_FG"> <p>@if (Page>1) { <a href="? page=1"> Home </a> <a href="[email protected] (prepage)"> Prev </a>} @for (inti = Countbegin; I <= countend; i++) { if(i = =page) { <aclass="Cur01"href="[email protected] (i)">@ (i) </a> } Else { <a href="[email protected] (i)">@ (i) </a>}} @if (page<PageCount) { <a href="[email protected] (nextpage)"> Next </a> <a href="[email protected] (PageCount)"> End </a>} total @ (PageCount) page</p> </div>
MVC Simple page-out code