MVC and asp.net MVC basic concepts
MVC is the abbreviation for Model-view-controller.
MVC divides the application into 3 major components: Model \ View \ Controller.
MVC is not unique to ASP.net, it's just a development idea. Struts2 in Java is also an MVC model.
asp.net mvc since release 1.0 in 2008, the latest version of ASP.net mvc as of 2014 is already 5.0.
asp.net mvc, starting with version 1.0, has opened the source code (source address: aspnetwebstack.codeplex.com).
asp.net MVC official address: HTTP://WWW.ASP.NET/MVC
Two, the mutual relation of the three main components of MVC
Views and models can be directly invoked in the controller
You can call the model in the view.
Model cannot call view
The model can qualify the data used in the view, but the model used in the view should be provided by the Controller
You can call the controller in the view (called by the form's submission and clicking the hyperlink in the view)
The relationship between ASP.net webform model and asp.net MVC model
Both are development models built on the ASP.NET web framework. So some of the features in ASP.net can be shared by both.
The WebForm programming model is a typical event-driven web model, while MVC is not.
WebForm's URL address is file-based, while MVC is based on action.
Iv. conventions in the ASP.net MVC
All controllers must be placed under the Controllers folder
All controller class names must end with controller
All models should be placed in the models directory.
All view files should be placed in the views directory.
All controller classes should inherit from the Controller class (essentially to inherit the IController interface)
The public method in the Controller class becomes the action (behavior)
If the view file is not found in the corresponding view directory, it will look for a view file with the same name in the views\shared directory
Return view () in action, by default, returns the file that is the same as the action name.
The default route (named Default) is registered in the Global.asax global application class, and the default route specifies controller defaults to home,action defaults to index, The parameter ID is an optional parameter. So in the URL address if you do not enter controller default access to the home controller, if you do not enter the action default access name is index action.http://localhost:54321/ Explanation: Based on default routing rules, equivalent to => Http://localhost:54321/Home/Index
HTTP://LOCALHOST:54321/HOME/INDEX/5 Explanation: The value 5 is automatically mapped to an argument with the name ID in the action.
Http://localhost:54321/Home/Index/5?name=jack&age=20 Explanation: The parameters include ID, name, and age three
Other
In the view file, there is a name called the Model property, which refers to the modeled data that is passed from the action. In order to use model data, we also need to set the type of model data in the ASPX view in the Inherits attribute of the <% @Page%> directive. Set model type in Razor view ...