First of all, I would like to say that the view of ASP. NET MVC is not a simple page. It implements the iview interface.
Public Interface Iview {
Void Render (viewcontext, textwriter writer );
}
In ASP. net mvc, a default view is provided, that is, webformview.
Then, the operations after the Web request arrives at the controller and the Controller returns the viewresult are like this:
- Viewresult itself executes the executeresult method. This method is the actionresult interface method, and viewresult is a class that implements this interface.
- Find the corresponding View
- Construct viewcontext
- Render
- Create viewpage
- Set the layout location
The main difference between viewpage (system. Web. MVC. viewpage) and the previous webpage (system. Web. UI. Page) is that the only and most important feature is page rendering. The viewstate, pageevents, and control hierarchies of webpage are discarded. SlaveCodeSee, viewpage implements the iview interface, and this interface has only one method, that is, render. It can be seen that its function is quite definite.
Viewengine is used to determine the view in MVC. That is, it is responsible for finding a specific view. The default viewengine is webformviewengine. If we want to change a view and do not want to continue using the ASPX page, we need to reconstruct a viewengine and register it in the system.
Layout is equivalent to masterpage. The difference is that it does not have the PostBack and form submission mechanisms. That is to say, it can only layout for viewpage.
Viewdata has already been mentioned before. View uses it to render the page. However, what we should say here is that a view only corresponds to a viewdata. If there are other partialviews In a view, the viewdata between them is not shared, the content is the same by default.
View also has some other knowledge, such as bindattribute and modelstate. I will study it again later. I feel a little confused when I encounter so many things for the first time.
Continue ......