Next, I want to learn MVC5 + EF6.2, mvc5ef6.2
Objective: 1. Learning mvc + ef
2. writing a diary is also a kind of supervision for yourself.
Lesson 1 starts from 0
Compared with the traditional WebForm development mode, ASP. net mvc development mode adds many "Conventions ".
Directly speaking about these "Conventions" can be confusing and too many things are easy to forget.
Unlike the official Microsoft tutorials, I try not to use scaffolding. Starting from the blank framework, I add the function step by step. Each time I add something that is enough, we can truly use it and understand every process.
Outline
- Overview
- Core concepts
- Create a basic framework from the blank
Overview core concepts
MVC, short for Model-View-Controller
Model encapsulates data related to business logic and the Data Processing Method
View provides users with an interactive interface
Controller controls Model and View
See the figure below. At present, we only need to understand this concept. Next we will start to build an empty framework and learn from it.
Create a basic framework from the blank
NOTE: Select Empty for the template. If you select MVC directly, additional code is generated.
NOTE: The box exactly corresponds to M, V, C
So far, a basic MVC solution has been established, which is basically empty.
Let's briefly introduce the RouteConfig. cs file.
Open Global. asax and note that the routing rules are registered when the program starts, as shown in the following box.
Next we will look at the specific routing rules. Open the RouteConfig. cs File
Note that there is a static method, which is the control of ing routing. This method defines routing rules.
Url: "{controller}/{action}/{id}" defines the URL format.
It will be explained in the future based on the actual URL address.
Regardless of the Model, we should first create the Controller and View
Right-click the Controllers folder and add it as shown in the figure below.
The Controller must end with the Controller (this is an ASP. net mvc Convention ).
Subsequent articles will show examples of user logon, so we will first create an AccountController.
The classes and folders in the box are added.
Open the newly created AccountController. cs and check that a method is automatically generated.
Public ActionResult Index ()
{
Return View ();
}
We call this Index an Action and the return type is ActionResult.
As you can see, this Action returns a View. Now let's create this View.
You can add a View directly in the Views folder (right-click the Views à Account folder)
The other is to use the Action in the Controller to add. This time we use the last method.
Open AccountController, right-click the Index method, and add it as shown in the figure below.
In this way, a View (Views à Account à Index. cshtml) corresponding to a specific Controller and Action (here, AccountController and Index) is added)
This View is the final front-end page. We add a line in the Body.
Right-click Index. cshtml and you can view the familiar HTML interface in the browser.
Note that the address xx/Account/Index in the browser
This address corresponds to the starting routing rule (url: "{controller}/{action}/{id}"). It should be easy to understand.
A typical execution process.
Remember this process. The subsequent process will be extended in this simple process.
Summary
MVC is much different from the previous WebForm development method, and the separation is more thorough.
This article focuses on setting up the basic concepts of ASP. net mvc.
The next article mainly introduces the uidesign of the View and some key HtmlHelper, which is easy to see from the front-end.
All subsequent articles will be extended using this example. If you have any questions, please comment on it :)
Haha contains the copy component.
Original article: Five-color blind MVC5 + EF6 full tutorial 1: Starting from 0