Today is the first day of study, the main summary of the following two questions. Because it is self-study, the summary may have a mistake to hope that everyone actively correct (smile).
1. What is MVC? Why use MVC?
2. How can I use MVC to quickly achieve entry-level development?
First, here's what MVC is: First, MVC is an architectural pattern; the second MVC is not equivalent to layer three; the third ASP . NET MVC is a product that is based on the UI layer in the three layer using the MVC idea, so what does the MVC architecture pattern mean? Of course, this architecture pattern was introduced in the 1980s. At that time there was no standard input, just to differentiate the input, output and logic processing. The development is divided into 3 parts, allowing developers to focus on and logical processing. The following is a biography of Intelligence podcast Zhao Xiao Hu taught in class
M---->mode (model) L
V----->view (view)
C----->controller (Controller)
。
With the development of the hardware, with the standard input, the left of the architecture model is no longer used, but many companies have to use the idea proposed by this model-division of development, so that better scheduling allocation of development work. This idea in the present development process is the embodiment of the three layer development--ui layer, business logic layer, data access layer (three layers need to pass the parameters need to use the model). Everyone should be more familiar with the three floor should not repeat it. ASP. NET MVC is actually a framework for further separation of the UI layer in layer three, which is a framework of UI layer. The UI layer is divided into input, processing, rendering return (the data involved in the model). Request to receive the input of this thing is called controller (controllers), the controller inside there are some actual implementation of the corresponding processing of something called action (behavior), the nature of the behavior is the method, these actions will invoke the underlying processing, after processing it to combine some model data encapsulation, The data is eventually handed to the view, which is eventually returned to the browser by the view completion rendering presentation. The razor rendering engine is powerful in that it can be rendered directly through the graphics card scheduler.
Note: The model and model layer described above is not a meaning, but in the actual development process we sometimes directly call the model layer in layer three, rather than write model, but this model is meaningful, many times we will do a strong type of page, The model we wrote ourselves at this time has meaning. The models in the model layer here correspond to some tables in the database, such as the Customer table and the order table, to display the customer name and the order name in the page, there is no model that contains both the customer and the order, this time we need to redefine a class in the model contains both the customer and the order, In a nutshell, the model in MVC is to show models, and the three-tier modeling is the data module that corresponds to table one by one in the database. Lori said so much, MVC is introduced here. Here's a second question. The reason why MVC is so obvious is that it allows for maximum decoupling between foreground and background. It also facilitates the task allocation of developers.
Create the first MVC project
Because the method is relatively simple, here is not, only to do simple text introduction
(1) Select file| New Project Options
(2) installed| in the left column of the New Project dialog box Templates section, select c#| Web Template list, on the right, select ASP. MVC4 Web application, name the program Mvcmusicstore (official website sample code) and click the OK button.
(3) Then there will be a Select a template dialog box to let you choose a project template.
Internet Application Templates: Contains the start-up of an ASP. NET MVC Web application that can be run immediately after the program is created and can see some pages. It also includes basic account management capabilities for the ASP. NET Membership System.
Intranet Application Template: The template is added as part of the ASP. NET MVC 3 tool update, similar to the Internet Application template, but its account management function is not for ASP. Membership System but for Windows accounts
Basic Template: This template is very small, and there is nothing more than a basic folder, CSS, and MVC application infrastructure. If you run an application created using the empty template, an error message will appear--you need to set the startup item. Why do you use the empty template? In fact, the basic template is designed by people with ASP. It can set and configure the program exactly as they think.
Empty Template: The basic template used to be called the empty template, but developers complained that the empty template was not enough. In MVC4, the first money of the empty template is renamed to Basic, the new empty template is empty, only the necessary assembly and the basic directory structure.
Mobile Application Template: This template is preconfigured with jquery mobile so that it starts creating a Web site that can only be accessed by mobile. The template includes a mobile visual theme, a touch-optimized UI, and AJAX support.
Web API Template: The ASP. NET API is a framework for creating HTTP services similar to the Intern application template, but he simplifies development for Web APIs. There is no user account management function.
For beginners, it is recommended to select the razor engine using the Internet Application Template view engine, tick the check box in front of select a unit test. Other can default, click OK
Here, you've created an MVC project.
(5) Click the Controller folder below right-click to add controllers (the controller is actually a class, the way to distinguish between classes and controllers is to see if he inherits System.MVC.Controller), click OK.
(6) Then add a view to the behavior in the controller, as shown in, select the index behavior, right-click to add a view
By default, the view name and the behavior name are the same, here we do not select the view and template, click Add, add a can put an HTML page of a. cshtml file. You can also configure the view page yourself by accessing the page in the form of a controller/behavior. If you configure the page yourself, you can add the name of the view you want to return by adding the parameter as shown, and then enter it in the browser: Port number/Controller name/INDEX1 can access Index1 this view page
Add a view to Index1 the same way you don't repeat it here. You can write what you want to show in the view.
Simple code introduction here, as to how the page access is determined by the route, MVC3 routing configuration in the global file configuration, MVC4 placed in a Routing configuration Class (Routeconfig), in the global file completion of the call, in detail.
ASP. NET MVC Learning notes summary (first day of self study)