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

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!

share|improve this question
  • 4
    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
  • 3
    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

3 Answers 3

active oldest votes
up vote 532 down vote accepted
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.310169 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO