MVC Learning Notes (4)

Source: Internet
Author: User

I showed you how to pass the values in the controller to the view, but how is it passed? What is the principle?

The view page.cshtml is compiled into a class at compile time, but this class inherits from the Webviewpage<object>

However, the parent class of this class is Webviewpage<object>, but Webviewpage<tmodel> 's parent class Webviewpage

The Webviewpage class also has the four properties of ViewData, ViewBag, TempData, model, but how do you pass this four attribute from the controller class to the four properties of the view class with the same name?

Let's look at the following:

Return a view method in the controller's method, the View method returns the Viewresult,viewresult class and inherits from the Viewresultbase class, we have a Executeresult method in the Viewresultbase class, As we can see, the parameter is the controller context object because the view method has multiple overloads, and if you return directly to view () without any arguments, the system will automatically determine this. ViewName is empty, if empty, then go to routedata inside to get the name of the action is the name of the view.

ViewContext viewcontext=new ViewContext (context,this. View,this. Viewdata,this. Tempdata,output);

As the above method, the controller context, Viewdata,tempdata, is uploaded to ViewContext, which is the view context.

This is then called.  View.render (Viewcontext,output); Renders the view context as a parameter, however this. View is a iview interface, so we're going to look at who implemented the iview interface, such as the Razorview and Webformview view engines, to find the Renderview method, In this case, the ViewData data in the controller is assigned to the ViewData, tempdata data of the view view.

MVC Learning Notes (4)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.