ASP. net mvc paging implementation: PagedList

Source: Internet
Author: User

More rights mean more responsibilities. In MVC, we almost no longer use various controls from Drag and Drop, so we are no longer limited by the functions provided by these controls, but of course, the benefits and convenience brought by these controls are lost. For example, GridView and its paging function. This article will use the defered execution feature of LINQ to implement a general PagedList for paging and navigation, so as to implement the ASP. net mvc paging function.

ASP. net mvc paging-CONTENT

To enable PagedList to have paging and navigation functions, we need to know the total number of rows of data and how many rows need to be displayed. Therefore, you can define such an interface.

To enable this generic PagedList to be "generic", you need to use generics .. Net has provided a good base class, we can inherit it, and at the same time implement IPagedList Interface

 

 

The last code in the PagedList constructor is explained as follows: index is the number of pages calculated from 0, which can be Null. pageSize is the number of records displayed on each page. Finally, the call to ToList () will make the IQueryable be executed, and the returned List will be added to the PagedList.

ASP. net mvc paging-Application

The PagedList is basically complete and is applied in practice. In the page file, you can set CSS based on the PagedList data to implement paging and navigation functions.

 

OK, We have done here. ASP. NET MVC paging implementation.

I didn't expect a good way to add the Controller information here, so I had to work hard for the moment.

  1. Add custom routes for ASP. net mvc applications
  2. Learning how to use ASP. net mvc Routing
  3. Analysis of URL Rewrite in ASP. NET
  4. Introduction to ASP. net mvc Framework
  5. Introduction to MvcAjaxPanel in ASP. NET MVC

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.