[Original] Mvc learning notes (1), original mvc learning notes
1. Create an MVC4 Project
Protected void Application_Start () {AreaRegistration. registerAllAreas (); WebApiConfig. register (GlobalConfiguration. configuration); FilterConfig. registerGlobalFilters (GlobalFilters. filters); // register a route. Only one RouteConfig is registered when the website is requested. registerRoutes (RouteTable. routes); BundleConfig. registerBundles (BundleTable. bundles );}Introduction to MVC Razor templates
In the ASPX module, we use <%>. However, in the Razor template, we use the @ symbol.
In the Razor template, we use @ {}, which indicates a code segment, which means to write C # code in "{}". The powerful aspect of the Razor template engine is that, it automatically recognizes the <> symbol and considers "<>" as the html code and outputs it with the @ symbol.
For example:
@ {String msg = "Haha"; <input type = "text" value = "@ msg"/> @ msg
<Text> Hello </text>}
Because Razor view engine recognition <> is there any good way to output the "hello" text in the code segment of the html page? You may want to use the label <span> Hello </span>. If we want to disable the label, we need to use the label <text> Hello </text>, this is the original text provided by the template, without tags.
Advantages of MVC development: differences between MVC and L3
I believe that many children's boots are often asked about the differences between MVC and Layer 3 during interviews. The homepage MVC is the development method of the presentation layer and has nothing to do with Layer 3. MVC is a design model of the presentation layer, A development method used to remove the UI and Business Code.
MVC knowledge
In MVC, the methods in the controller must be defined as public and the Controller class must be public if they are to be accessed by browsers. Otherwise, they cannot be accessed, the Controller class name must end with the Controller and inherit from the Controller class. in net mvc, the agreed Controller must inherit from the Controller at the end, but you can do the same, but you need to configure it, but try to follow the agreement, this is very convenient, this is the so-called Convention that exceeds the configuration.