Development and application of asp.net viewengine

Source: Internet
Author: User
Tags httpcontext

A MVC1 version of the Viewengine

From the above figure, we can know: (1) When the client sends the request, Defaultcontrollerfactory generates our controller according to the RequestContext object and Controllername. The controller viewdatadictionary will hold the relevant data and pass it through Viewengine to the view.

Public virtual IController Createcontroller (RequestContext 

RequestContext, string controllername)
{
    Type Controllertype = this. Getcontrollertype (RequestContext, controllername); Type = this 

. Getcontrollertypewithinnamespaces (RequestContext.RouteData.Route, Controllername, 

namespaces);
    return this. GetControllerInstance (RequestContext, Controllertype);
}
    
Protected internal virtual IController getcontrollerinstance (RequestContext requestcontext, Type 

controllertype)
{
    return  (IController) activator.createinstance (controllertype);//Reflection
}

(2) In our previous version of MVC, Controller owns Viewengine properties. Let's take a look at the following code: Viewengine How to handle view and respond to the client according to Viewcontext,viewlocator??

public void Renderview (ViewContext viewcontext)
        {
            string viewlocation = Viewlocator.getviewlocation ( ViewContext, 

viewcontext.viewname)//Get the relative file path string ViewPath of view based on ViewContext and related content
            ViewContext.HttpContext.Request.MapPath (viewlocation););//Get View

's absolute file path
            string viewtemplate = File.readalltext (ViewPath)//Read the contents of the file
            irenderer renderer = new Printrenderer ();
            Viewtemplate = renderer. Render (Viewtemplate, viewcontext);//Regular expressions deal with the content, the

difficulty!
            ViewContext.HttpContext.Response.Write (viewtemplate);//Send response to client
        }

From the above code, we can see clearly that the overall framework is such a stark "request---> Response." Although the code is in the past version, it still makes it easier to understand the details of the process.

For custom viewengine of previous versions please refer to http://blog.maartenballiauw.be/post/2008/05/creating-a-custom-viewengine- For-the-aspnet-mvc-framework.aspx

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.