ASP. NET MVC basis

  • 2021-01-25 07:27:17
  • OfStack

1. MVC and ASP.NET and MVC basic concepts

MVC is short for Model-View-Controller.
MVC divides an application into three major components: Model, View, Controller.
MVC is not specific to ASP.NET is a development concept. struts2 in java is also an MVC model.
ASP.NET MVC released version 1.0 in 2008, as of 2014 ASP.NET MVC latest version has been 5.0.
ASP.NET MVC has been open source since version 1.0 (source address:
ASP. NET MVC website address: http: / / www asp. net/mvc

2. The relationship between MVC3 components

You can call the view and model directly from within the controller

The model can be invoked from within the view.

The model cannot call the view

The model can qualify the data used in the view, but the model used in the view should be provided by the controller

The controller can be called from within the view (by submitting the form in the view and clicking on the hyperlink)

3. ASP.NET Webform model and ASP.NET MVC model

Both are development models based on ASP.NET Web framework. So ES69en. ES70en has some functions that can be shared by two users.

The Webform programming model is typical of the event-driven web model, whereas MVC is not.

Webform's URL addresses are based on the file system, while MVC is based on Action.

4. Conventions in ASP.NET MVC

All controllers must be placed in the Controllers folder

All controller class names must end in 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 the Icontroller interface).

The public method in the controller class is called Action(Behavior).

If the view file is not found in the corresponding view directory, a view file with the same name in the Views\Shared directory is looked for

return view() By default, a view file with the same name as Action is returned.

The default route (named Default) is registered in the Global.asax global application class. The default route specifies that Controller is Home by default and Action is Index by default. The parameter id is optional. So in the URL address if you don't enter controller default access to the Home controller; If you do not enter action. The default name of access for Index action http: / / localhost: 54321 / interpretation: according to the default routing rules, equivalent to = > http://localhost:54321/Home/Index
http: / / localhost: 54321 / Home/Index/explanation: numerical 5 will be automatically mapped to action name for id parameter.
Http://localhost:54321/Home/Index/5?name=jack & age=20 Explanation: The parameters include id, name and age3


In the view file, there is a property named Model, which refers to the model data passed from Action. To work with the model data, we also need to be in the aspx view < %@Page % > Set the type of the model data in the Inherits property of the directive/set the model type...... in the Razor view

Related articles: