1, the list page, the General List page is mainly used to display data, the list page provided in this article, data display and paging, delete operations, new and modified operations. Because there are some people in the garden that are using ViewData when using MVC for data display, this is the strong type display data. Add a new view, in the first line of code you can see
Copy Code code as follows:
<%@ Page language= "C #" inherits= "system.web.mvc.viewpage<dynamic>"%>
The type of view can be defined here, and it is easier to operate, as we define here
Copy Code code as follows:
<%@ Page language= "C #" inherits= "system.web.mvc.viewpage<web.models.pagedata<web.models.users>>"% >
This returns a paging collection entity class, which defines the entity class
Copy Code code as follows:
<summary>
Paging Query Recordset class
</summary>
<typeparam name= "T" > Pass class type </typeparam>
public class Pagedata<t>
{
<summary>
Gets or sets the paging recordset returned by the query
</summary>
Public list<t> GetDate = new list<t> ();
<summary>
Gets or sets the total number of records that meet the query criteria
</summary>
public int Count {get; set;}
<summary>
How many pages per page
</summary>
public int PageSize = 5;
<summary>
How many pages are currently
</summary>
public int PageIndex {get; set;}
}
After the controller processing, return the relevant parameters, including the required display data, total records, page numbers, the current first page of information. Since the type has already been defined in the list page, it can be invoked directly through model.
As you can see from the diagram above, the getdate of this property is a generic collection of data so that we can loop through the display. If paging, according to the number of pages passed to the controller, retrieve the data, fill, and then return, and then display, here can be implemented to display data and paging function. Here a little introduction to the next page of the plug-in, with the jquery.pagination, if you are not familiar with the use of words, the garden has a detailed introduction of the article.
The controller gets the relevant data from the database and fills it into the entity class so that the direct call in the view is OK. Here is the writing in the controller.
Copy Code code as follows:
$ (function () {
Paging parameter settings
$ ("#Pagination"). pagination (<%=model.count%>, {
Callback:pageselectcallback,
Prev_text: "«Previous Page"///Prev Button text
Next_text: "Next Page»",///Next button text
Items_per_page: <%=model.pagesize%>,//How many shows per page
Num_display_entries:5,///////////The number of page entries displayed in the
Current_page: <%=model.pageindex%>,//Current number of pages
Num_edge_entries:1,//The number of entries displayed on both sides of the page
Link_to: "page=__id__"
});
});
function Pageselectcallback (page_id, JQ) {
callback function
}
2, add the operation. Let's first define an entity class.
Copy Code code as follows:
<summary>
User ID
</summary>
public int UID {get; set;}
<summary>
Login account
</summary>
public string UName {get; set;}
<summary>
Login Password
</summary>
public string Upassword {get; set;}
Then in the new page we need to define two input, and then enter the login account and login password, note that in the definition of two input, please be sure to set the name of the input attribute to the entity class, of course, our view also need to define the type of users (entity class, class name), Set the action and Method properties.
Copy Code code as follows:
<%@ Page language= "C #" inherits= "system.web.mvc.viewpage<web.models.users>"%>
<form action= "/demo/add/" method= "POST" >
<table>
<tr>
<td> Login Account:</td>
<td><input type= "text" name= "UName"/></td>
</tr>
<tr>
<td> Login Password:</td>
<td><input type= "Password" name= "Upassword"/></td>
</tr>
<tr>
<TD colspan= "2" align= "center" ><input type= "Submit" value= "submitted"/></td>
</tr>
</table>
</form>
Because MVC automatically maps the form to fields in the entity class, it's OK to get the entity class directly from the controller. Because I see some children's shoes get the data by request.form[""] to get the value.
Copy Code code as follows:
[HttpPost]
To add operations
Public ActionResult ADD (Users model)
{
Here's what you can do for new things
Bll.add (model);
Return redirecttoaction ("List");
}
This allows the values in the form to be saved in the entity class, without having to get the assignment. Modified words similar to this, here is not very meticulous to speak, at the end of the article will provide demo download.
Click to download