Manage your viewengine (wirte by myself)

Source: Internet
Author: User

I think anybody wowould have the same problem as my that have a little big MVC project and Of couse we have alot views to share, its necessary for reuse, but sadlly our mvc3 razor view only provide one share Dir of "share ".

If you type viewengin in zzk, you will c most results are tell you to create a new view engine, its too complex to only add a share directory.

So my solution is to modify the ve, firstly you shoshould know, its init two default viewengine:

 
StaticViewengines ()
 
{
Viewenginecollection engines =NewViewenginecollection ();
 
Engines. Add (NewWebformviewengine ());
 
Engines. Add (NewRazorviewengine ());
 
_ Engines = engines;
}
 
 

My code (because no aspx or other webforms need in my website so no webform ve needed !)

 
Viewengines. Engines. Clear ();
 
VaR RVE =NewRazorviewengine ();
VaR newloactions = RVE. partialviewlocationformats. tolist ();
 
Newloactions. addrange (NewList <String>
 
{
 
//"~ /Views/{Controller: 1}/{0}. cshtml"
"~ /Views/XXX/{0}. cshtml"
 
});
 
RVE. partialviewlocationformats = newloactions. toarray ();
 
Viewengines. Engines. Add (RVE );

 

Hope can help you too!

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.