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