Home How do I specify different Layouts in the ASP.NET MVC 3 razor ViewStart file?

# How do I specify different Layouts in the ASP.NET MVC 3 razor ViewStart file?

user6961
1#
user6961 Published in September 20, 2018, 10:23 pm

I would like to have 2 separate Layouts in my application. Let say one is for the Public section of the website and the other is for the Member side.

For simplicity lets say all the logic for each of theses sites is wrapped neatly into 2 distinct controllers.

• PublicController
• StaffController

And that they each have a corresponding Layout for all the View under each.

• _PublicLayout.cshtml
• _StaffLayout.cshtml

How do I use the _ViewStart.cshtml file to specify that all View's / Action under "Public" use the PublicLayout and everything under "Staff" use the StaffLayout?

Thanks!

• Just in case: if you want to remove the layout for a given Razor view, just set Layout = null; – Leniel Maccaferri Mar 19 '14 at 5:53
• Just as a comment to your example, you should probably not have controllers named Public and Staff. Controllers are most often implemented as the entry point to CRUD-like action on certain key business entities, like EventController, UserController, or the like. If your application is reasonably big, the responsibility of a Public/Staff controller would be way to wide. Consider Areas instead. msdn.microsoft.com/en-us/library/ee671793%28VS.100%29.aspx You might be aware of this but someone else reading this might get the wrong idea, so just for the record. – Alex Jun 26 '14 at 17:08