Familiar with: Asp.net mvc3 loading cshtml file custom paging + Query

Source: Internet
Author: User
Last time I wrote this article: conventional Introduction: Asp.net MVC 3 loading cshtml files to create custom pages

Problems: simple data list, paging OK, but with other external factors, such as query, sorting, and paging, how can we combine them?

How to combine paging with query and sorting?

My idea is to query and sort data by page.

1. the query condition is changed, the page number is reloaded, and the current page starts from 1.

2. the page number generated after the query saves the corresponding parameters and values of the query to simulate the query + paging effect.

 

Expand the paging control so that it can contain other parameters.

Common parameter passing Methods: URL-based value passing and form-based value passing

Common data formats: Text and JSON

 

Change Original Design:

Datatype parameter type text/JSON

 

Pagemodel page types include:

Pageindex page index

Pagetext page display text

 

Pager paging controls

The pagertemp paging control loads the cshtml or ascx name.

Pagerid: the ID of the paging control.

Pagination of pagershow

Pagesize: number of records displayed per page

Curpage index of the current page

The minimum number of pagenum pages displayed[Offset]

Total totalpage pages

Total totalsize Record Data

List <pagemodel> page number list

Controllername controller name

Actionname action name

Datatype Data Format

Dictionary <string, string> parameter list

Pagedata

Pagehelper pagination control generation class, extended htmlhelper used to create pagination Control

Public static mvchtmlstring Pager (this htmlhelper helper,
String pagerid, // Paging Control ID
Int curpage, // Current page number
Int totalsize, // Total number of records
String pagertemp = "_ pagertemp ", // Pagination control Template
Int pagesize = 10, // 10 entries per page
Int pagenum = 5, // Number of displayed page numbers

String datatype = "text ",// The default value is the URL value.
Dictionary <string, string> parameters = NULL// Parameter list

){

// Create a paging Control

}

 

_ Pagetemp: page control display template

 

To sum up, we need to clear curpage as 1 when the query or filter condition changes.

Click to download

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.