Add reference to view: @using WEBDIYER.WEBCONTROLS.MVC;
Use-Time code:
<div id= "pagination" > @Html. Pager (model.datalist, new pageroptions { pageindexparametername = " PageIndex ", Showprevnext = True, firstpagetext =" Home ", prevpagetext =" Previous page ", nextpagetext =" Next Page ", Lastpagetext = "Last", Horizontalalign= "Right", pageritemtemplate= "{0}"}) </div>
Background controller:
Public actionresult newslist (int tid = 1, int PageIndex = 1) { int PageSize = ten; int RecordCount = db. Articlesinfos.count (); int pagecount = (recordcount/pagesize) + (RecordCount% PageSize > 0? 1:0); Viewdata["tid"] = tid; pagedlist<models.articlesinfo> list = db. Articlesinfos.orderbydescending (c = c.id). AsQueryable (). Topagedlist (PageIndex, PageSize); Viewmodel.mvcpagermodel<models.articlesinfo> model = new Viewmodel.mvcpagermodel<models.articlesinfo> ( ); Model. PageCount = PageCount; Model. RecordCount = RecordCount; Model. PageSize = PageSize; Model. PageIndex = PageIndex; Model. DataList = list; return View (model); }
Paging class:
public class vmnewslistpage<t> {public int PageIndex {get; set;} public int PageCount {get; set;} public int RecordCount {get; set;} public int PageSize {get; set;} Public pagedlist<t> Articlesinfos {get; set;} }
Demo
@{viewbag.title = "Newslist"; Layout = "~/views/shared/_layoutpageone.cshtml";} @model mvcapplication1.viewmodel.mvcpagermodel<mvcapplication1.models.articlesinfo> @using WEBDIYER.WEBCONTROLS.MVC, @section header{}<div class= "Pageban" style= "Background-image:url (/images/ 20141002091135849.jpg); " ></div><div class= "contain" > <!--/* content */--> <div class= "left" > <div class= "sideb Ar "> <div class=" title "> News </div> <ul class=" sub "> <LI>&L T;a href= "Newslist?tid=1&pageindex=1" id= "a_group_1" class= "@ (Convert.ToInt32 (viewdata[" tid "]) = = 1? "Aon": "") "> Company news </a></li> <li><a href=" newslist?tid=2&pageindex=1 "id=" A_group _2 "class=" @ (Convert.ToInt32 (viewdata["Tid"]) = = 2? "Aon": "") "> Industry Dynamics </a></li> </ul> @Html. Partial (" Ucleftcontact ") </div > <!--/* Body */--> <dIV class= "Main" > <div class= "Current" > <em> you are here: <a href= "Index" > Home </a> > <a href= "[email protected][" T ID "]&pageindex=1" id= "A_group_nav_1" > News </a> > <a href= "[email protected][" Tid "]& Pageindex=1 "id=" A_group_nav_2 ">@ (Convert.ToInt32 (viewdata[" Tid "]) = = 1? "Company News": "Industry Trends") </a> > </em> <b id= "A_group_nav_3" >@ (Convert.ToInt32 (Vi ewdata["Tid"]) = = 1? "Company News": "Industry Trends") </b> </div> <!--/* News list */--> <dl class= "NewList" > @foreach (var item in model.datalist) {<dd> <div class= "pic" > <a href= "[email protected]" target= "_blank" title= "@item. Title "> </a> </div> <div class= "Text" >
Reference: http://www.webdiyer.com/mvcpager/
MVC Pager Use