Specifying Layout From Another File Gives Compilation Errors (ASP.NET MVC3/Razor)

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).

1 Answer

Leave a Reply

Your email address will not be published. Required fields are marked *

You can use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>