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>