View Engine View engine (1)

Source: Internet
Author: User

MVC 3 allows you to create your own view engine without using the built-in razor view or apsx view. The following describes how to create a custom view engine.

First, view engine inherits from the iviewengine interface. The iviewengine interface is defined as follows:

 1   Public   Interface  Iviewengine {  2 Viewengineresult findview (controllercontext, String  Viewname,  3   String Mastername, Bool  Usecache );  4  Viewengineresult findpartialview (controllercontext,  5   String Partialviewname, Bool  Usecache );  6   Void  Releaseview (controllercontext, iview view );  7 }

The role of the view engine is to convert the request to viewengineresult. the parameter of the first and second methods requires a controllercontext, A viewname, A mastername and a parameter that specifies whether previous results can be reused in the cache. The last method releaseview is called when the view is not used and will be released.

The viewengineresult class allows the view engine to respond to a request when the view needs to be displayed. You can create viewengineresult using one of the following constructor types:

1. Public viewengineresult (iview view, iviewengine viewengine );

The constructor parameters are inherited from the iview interface and view engine.

If your view engine does not provide a view that responds to a request, you can use the following constructor:

2. Public viewengineresult (ienumberable <string> searchlocations );

The constructor of this version looks for view files in several places. If the view files cannot be found, an error message is displayed.

 

The last block in the view engine system is the iview interface, as shown in the following figure.CodeAs shown in:

1 NamespaceSystem. Web. MVC {2 UsingSystem. IO;3 Public InterfaceIview {4 VoidRender (viewcontext, textwriter writer );5 }6}

We pass an iview object to the constructor of the viewengineresult object, and then return the view engine method. The MVC Framework calls the render method. The viewcontext context contains the request information from the client. textwriter will output some content to the client.

 

The best way to learn the relationship between iviewengine, iview, and viewengineresult is to create a view engine.

Next articleArticle, We will create a view engine of our own.

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.