Small MVC example
[Conventions are better than configurations]
1. Right-click the Mode data layer to add a new item and connect to the database with linq
(Do not directly control linq on the control layer. Create a class on the data layer to operate the database)
2. Right-click the Mode data layer and add a class to complete database operations. The class name is Carda.
3. In the Carda class, add, delete, modify, and query the database. For example
4. Go to the Controllers control layer code and write the following code:
5. upload the data to the Views view layer, right-click the ActionResult action result method to add the view, and select ASPX for the view engine. Set the website style on the webpage.
6. note that the connection in <a href = ""> </a> In the view layer must not directly write the address of the connection, be sure to write the connection to the control layer, such as <a href = "/home/delete"> </a>. Hello is the name of the control layer controller, and delete is the deletion method written by the control layer.
Files in solution manager of the project
· The Name Of The control layer controller is hello
· The method for connecting to the database at the data layer is DataClasses, and the class for controlling the database is Carda.
· The folder Name of the view layer is hello, which is the same as that of the control layer controller; the view added at the control layer will create a webpage in aspx format in the corresponding folder of the Views view layer.
Redirection method: