Introduction to Asp.net Mvc paging method

Source: Internet
Author: User

In the mvcweb project, there is a global. asax. cs file with the following code:

Routes. maproute (
"Default", // route name
"{Controller}/{action}/{id}", // url with parameters
New {controller = "index", action = "index", id = urlparameter. optional} // default value of the parameter
);

In pagecontroller. cs, we use:

Public actionresult index (string id)
        {
Return view (new models. page (id ));
        }

The names of the red font must be the same.

 

Let's take a look at some code of page. cs in the models Directory:

Public page (string para)
        {
Int pagesize = 10;
Pageparse sm = new pageparse (para, httpcontext. current. request. querystring );
Int currentpage = strtoint (sm ["page"], 1 );

Datasource ds = new datasource (); // initialize the data source
Int totalcount = ds. objlist. count; // The total number of records.

Var q = ds. objlist. asqueryable <objectdata> ();
If (currentpage> 0) q = q. skip (currentpage-1) * pagesize );

Alist = q. take (pagesize). tolist ();
Paging = new paging <objectdata> (pagesize, currentpage, alist, totalcount, sm. pagingurl );
        }

In asp tutorial x, the page is displayed as follows:

<Div style = "border-bottom: 1px solid # d7d7d7;">
<Label>
Total <em> <% = model. paging. totalcount %> </em> records </label>
<Div>
<% = Model. paging. getstr () %>
</Div>
</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.