_ViewStart not used after Custom ViewEngine

Does anyone know if there is a reason _ViewStart.cshtml will not be retrieved using Custom ViewEngine in MVC 3?

My views live in

~ \ UI \ Views \

~ \ UI \ Views \ Shared \

where ViewStart is located in ~ \ UI \ Views_ViewStart.cshtml.

I cleaned up the existing RazorViewEngine and replaced it with mine in global.asax, and all views are resolved correctly, except that none of the layout pages apply unless I specify it separately in each view.

My engine code format is:

this.ViewLocationFormats = new[] { "~/UI/Views/{1}/{0}.cshtml", "~/UI/Views/Shared/{0}.cshtml" }; this.PartialViewLocationFormats = new[] { "~/UI/Views/Shared/{0}.cshtml", "~/UI/Views/Shared/Partial/{0}.cshtml", "~/UI/Views/{1}/Partial/{0}.cshtml" }; this.AreaMasterLocationFormats = new[] { "~/UI/Views/Admin/Shared/{0}.cshtml" }; this.AreaPartialViewLocationFormats = new[] { "~/UI/Views/Admin/Shared/{0}.cshtml", "~/UI/Views/Admin/Shared/Partial/{0}.cshtml" }; this.AreaViewLocationFormats = new[] { "~/UI/Views/Admin/{1}/{0}.cshtml" }; this.MasterLocationFormats = new[] { "~/UI/Views/{1}/{0}.cshtml", "~/UI/Views/Shared/{0}.cshtml" }; 

Thanks in advance, Scott

+4
source share
1 answer

Stupidity won this time, unfortunately. I based my custom ViewEngine on some code that I referenced from the article. Inside the article, they detailed redefinition for CreateView. One of the boolean parameters (runViewStartPages) is set to false, but since it was not a named argument, I skipped it.

 public class XyzViewEngine : RazorViewEngine { protected override IView CreateView(ControllerContext controllerContext, string viewPath, string masterPath) { return new RazorView( controllerContext, viewPath, masterPath, true, //<--- this drives whether to use _ViewStart pages. It was set to false FileExtensions, ViewPageActivator ); } } 
+2
source

All Articles