I have a standard ASP.NET MVC3 application. In _ViewStart.cshtml, I used to have:
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
Everything worked, and life was good. Now, I want to move the layout to a directory that’s modifiable at runtime; something like:
@{
Layout = "~/Content/Themes/" + SomeClass.FolderName + "_/Layout.cshtml";
}
(Where potentially I would call SomeClass.FolderName = "blah" in my code.)
Pasting a copy of the old Shared/_Layout.cshtml into the directory specified by SomeClass.FolderName unfortunately gives me several compilation errors, such as ViewBag, Url, and Html not existing (but strangely enough, User.Identity is still accessible).
What am I missing, and how can I make this work?
Edit: Based on this question, I pasted my web.config from /Views into the directory, and it seems to work — but a CSS file referenced gives me a 404 (eg. {SomeClass.FolderName}/site.css).
The MVC template configures Razor for MVC views in
~/Views/Web.config.You need to copy the Razor section in Web.config to the other folder.