I group my views, controllers and models. Structure
~/Controllers -- /_Shared -- -- /Views -- -- /Content -- -- /Scripts -- /Home -- -- /Models -- -- /Content -- -- /Scripts -- -- /Views -- -- HomeController.cs -- /Account -- -- /Models -- -- /Views ...
Views and partial views work, but layouts (master views) do not work . When I specify the layout in the .cshtml file, for example:
@{ Layout = "SimpleSharedLayout"; }
I get this error: The "SimpleLayout" layout page was not found in the following path:
"~ / Controllers / Recording / Views / SimpleSharedLayout".
Asp.NET only looks for the layout in the current controller directory, and does not look at the shared folder * (which is in ~ / Controllers / _Shared / Views) *
Although this one works just fine.
@Html.Partial("SharedPartialView")
I need to specify layouts with full paths like
@{ Layout = "~/Controllers/_Shared/Views/SimpleSharedLayout.cshtml"; }
It is not difficult, but I am crazy because of the inability to make it work.
Using IIS Express, VS 2012, .NET 4.5
Do you have an idea of ββwhat I am missing?
My view engine:
public class AreaViewEngine : RazorViewEngine { public AreaViewEngine() { AreaViewLocationFormats = new[] { "~/Controllers/{1}/Views/{0}.cshtml", "~/Controllers/_Shared/Views/{0}.cshtml"}; ViewLocationFormats = AreaViewLocationFormats; AreaMasterLocationFormats = new[] { "~/Controllers/_Shared/Views/{0}.cshtml" }; MasterLocationFormats = AreaMasterLocationFormats; AreaPartialViewLocationFormats = new[] { "~/Controllers/_Shared/Views/{0}.cshtml", "~/Controllers/{1}/Views/{0}.cshtml"}; PartialViewLocationFormats = AreaPartialViewLocationFormats; } }