I wrote an MVC paging article last year.
I used an ASP. NET MVC file to share it by page.
Now release a release version
The ipagedlist used in it is hard to remember where to copy it. Haha
Here I will not take the ipagedlistCodePaste it out. You can download the demo.
Data paging in the background
Public Actionresult Index ([ Defaultvalue (1)] Int P ,[ Defaultvalue (10)] Int Pagesize ){ VaR Model = Database . List . Orderbydescending ( Z => Z . ID ). Topagedlist ( P -1, Pagesize ); Return View ( "Index" , Model );}
I prefer to use defaultvalue recently.
Of course, it can also be written
Public Actionresult Index ( Int ? P , Int ? Pagesize ){ P = P ?? 1; Pagesize = Pagesize ?? 10; VaR Model = Database . List . Orderbydescending ( Z => Z . ID ). Topagedlist ( P -1, Pagesize ); Return View ( "Index" , Model );}
Here, the first parameter in the topagedlist extension method is index.
I am too lazy to change it to page, so I used the p-1.
Console call
<%@PageLanguage="C #"Masterpagefile="~ /Views/shared/site. Master"
Inherits="System. Web. MVC. viewpage <mvcdemo. ipagedlist <mymodel>"%>
<% = Html . Pagerbar ( Viewdata . Model ) %> < Table > < Thead > < Tr > < Th > ID </ Th > < Th > Surname? Name? </ Th > < Th > Mailbox box? </ Th > < Th > ? Persons? Master region page 3 </ Th > < Th > Súri? </ Th > < Th > & Nbsp; </ Th > </ Tr > </ Thead > < Tbody > <% Foreach ( VaR Item In Viewdata . Model ){ %> < Tr > < TD > <% = Item . ID %> </ TD > < TD > <% = Item . Name %> </ TD > < TD > <% = Item . Email %> </ TD > < TD > <% = Item . URL %> </ TD > < TD > <% = Item . Birthday . Tow.datestring () %> </ TD > < TD > <% = Html . Actionlink ( "Edit" , "Edit" , New { ID = Item . ID },
New { @ class = " D " , width =600}) %> TD >
tr > <% } %> tbody > table >
Style controls are similar to those in the previous article. I will not talk about them here.
In Demo:
Download Demo:/files/francis67/mvcdemo.rar