Overview
MVC is an idea, based on the idea that there are many frameworks, like struts in Java, what is the idea?
MVC thought
Thought, that is, the idea, to know what this idea is, you need to know the idea because of what produced, to know, there is no unprovoked hatred, so, the idea is not possible in the absence of any cause of the situation, then what is the trigger of the idea of the emergence of it and pushed it to the climax?
To know this, first, let's analyze the state of our web programming world before MVC really arrives. Web development at the time, mainly in the development of WebForm, that is, the event-driven page of ASP., so that the development of the way to the data and the display data side tightly coupled, so that the two changes in the impact of the other side is very large.
For example: The foreground page drag and drop a server-side control, the background code directly manipulate the control, so that if our requirements become this control does not need to display, then we need to do is to remove the control, and find the background operation of the control's code, and then remove.
After reading this example, may not sound very deep, at this point, you can let it zoom in, so that its logic more complex, such as: The background code has this server-side control of a lot of events, each event, and the operation of a lot of other service-side controls (property modification, call method), and the foreground also has a corresponding impact ( Return JS script Modify style and so on), so you want to remove this control, the equivalent of this page turned the sky, of course, this is just a page, if it is more than such a page? This is very likely to re-develop our UI layer.
The idea of MVC is to completely decouple the data provider (Control) from the data display (view), that is, We split our previous ASP into two separate blocks: A and B, the bridge between Block A and block B is data, a gives B data, B loves how those data can show that data, it doesn't affect a at all, that is, in the MVC framework, you can't use server-side controls in ASP.
two architectures developed by the MVC framework
When using MVC, we often hear about using MVC to build a framework, so there are generally two ways, one is that MVC is just a UI layer of the architecture, one is the VC is the UI layer, M is all the layers below (specific below how many layers, it depends on how you specifically build this project), I prefer the first, that is, MVC is just a framework for the transition layer, why do you think so? Also mentioned above, the communication between V and C is the medium is the data, this data is M, from here we can know, C to v pass a m, then this m property should contain all the data to be displayed in V, from here, M is actually Formmodel (Pagemodel), There is no semi-gross relationship with the entity layer in the three-tier architecture.
Convention is greater than configuration thought
In the. NET MVC framework implementation, there is an important idea is that the Convention is greater than the configuration, we know that when we use MVC to develop the Web, the user requests the method in C, then, the C method will be the corresponding entity (possibly other things, binary stream, etc.) to a V, this time, The interesting thing came, namely: to the end of the V, this is the determination of where should be achieved? is to put it in the configuration file configuration, or write in the program, Microsoft is written in the program, Java struts is a configuration file (this did not experiment).
Configuration file more flexible, but, think of a method in C, I will write in a configuration file, I am a bit cold; Microsoft's writing in the program is the idea that the Convention is greater than the configuration, that is, when the C method creates V, the system automatically creates a folder (with the same name as C), the View convention of V is the same , at the same time, the method in the corresponding V, the system will automatically find and C folder in the same name, and the method name of the same name of the view to display, of course, this convention is not dead, we can also write some method parameters to make the corresponding view.
Summary
When I studied. NET MVC, I was shocked too much, those packaged JS code, jquery Library, check (front and back), asynchronous (implicit non-implicit), Httphelper, routing rules, and so on, extracted too good, encapsulation is great.