ASP. NET MVC uses Mvcpager for paging

Source: Internet
Author: User

Method-:

1, the method of using Pagedlist to turn pages in service

Writing one:

<summary>
More on the Policy and Regulation list page
</summary>
<param name= "page" > page number of pagination </param>
<param name= "Sid" > Department Code </param>
<returns></returns>

Public pagedlist<c_newss> Lists (int? page)
{

EXPRESSION<FUNC<C_NEWSS, bool>> filter = T = = true;
int pageSize = 10;//The number of displays per page


Filter = filter. and (t = T.news_kind ==171);

using (jy_villageentities db = new Jy_villageentities ())
{
Return DB. C_newss.where (filter). OrderByDescending (t=>t.pub_date). Topagedlist (page 1, pageSize);


}

}

Two:

Public pagedlist<p_finances> GETPAGEDLISTBYDWDM (string dwdm, int? page)

{
int pageSize = 10;
using (jy_villageentities db = new Jy_villageentities ())
{
Return DB. P_finances.where (item = Item). DWDM = = DWDM). OrderByDescending (item = Item). Year). ThenByDescending (item = Item). Month). Topagedlist (page 1, pageSize);
}
}

2, the method of invoking page flipping in action

<summary>
Policies and regulations more list data
</summary>
<param name= "Classno" ></param>
<param name= "Sid" ></param>
<returns></returns>
Public ActionResult List (int? page, int? sid)
{
Viewdata.model = Homeservice.morelist (Classno, sid);

Viewdata.model = homeservice.lists (page);
return View ();
}

3, using In view

@using WEBDIYER.WEBCONTROLS.MVC
@model webdiyer.webcontrols.mvc.pagedlist<community.site.models.c_newss>

<div id= "PageContent" >

<ul>

foreach (var item in Model)
{
<li><a href= "@Url. Action (" News ", new {Newsno = item.id})" ><span>@ (item. Createon) </span>@ (item. Title) </a></li>
}


}
</ul>
</div>

Use the Mvcpager plugin to directly use the @html.pager control

@* @Html. Pager (Model, new pageroptions {pageindexparametername = "page", CssClass = "pagination"}) *@

Use the button you wrote with the following
<div class= "page",
<span class= "Pageleft" ><a href= "@ Url.action ("List", new {page = Model.currentpageindex = = 1?) "": (model.currentpageindex-1). ToString ()}) "
</a></span><span class=" Pagenum "> @Model. CurrentPageIndex/@ Model.totalpagecount</span>
<span class= "pageright" ><a href= "@Url. Action (" List ", new {page = ( Model.currentpageindex + 1)}) "></A></SPAN>
</div>

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.