Reputation: 658
Does anyone know if there is a reason why _ViewStart.cshtml wouldn't get picked up with a Custom ViewEngine in MVC 3?
My Views now live at
~\UI\Views\
~\UI\Views\Shared\
with ViewStart being at ~\UI\Views_ViewStart.cshtml.
I've cleared out the existing RazorViewEngine and replaced it with mine in the global.asax and all the views resolve properly except none of the layout pages get applied unless I specify it individually in each view.
My engine path format code 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
Upvotes: 4
Views: 666
Reputation: 658
Stupidity won this time, unfortunately. I had based my custom ViewEngine off some code I referenced from an article. Within the article, they detailed the override for CreateView. It had one of the boolean parameters (runViewStartPages) set to false but since it wasn't a named argument, I missed over 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
);
}
}
Upvotes: 2