This is definitely possible, I think you just missed something.
I have tested this myself using the view engine you supplied (copied and pasted verbatim). I am not seeing the same behavior as you. I have two _ViewStart.cshtml
files, one at ~/Framework/Views/_ViewStart.cshtml
, and one at ~/Views/_ViewStart.cshtml
.
When I run a view within ~/Framework/Views/
, it uses the _ViewStart.cshtml
in the Framework folder. When I run a view within ~/Views/
, it uses the _ViewStart.cshtml
in the Views folder.
Double checking the code in RazorViewEngine
using DotPeek also confirms that this is exactly how it should behave. The view engine starts checking in for a file named _ViewStart.cshtml
within the same folder as the view being rendered, and then walks up the directory tree until it gets to the root of the application.