Posted By

lance on 01/15/14


Tagged

MVC


Versions (?)

Load different layout page based on controller


 / Published in: C#
 

How to load a different layout page for specific controller in case you need to change includes etc. Add to _ViewStart.cshtml

  1. @{
  2. string currentController = ViewContext.RouteData.Values["controller"].ToString();
  3. if(currentController == "PCA" || currentController == "pca")
  4. {
  5. Layout = "~/Views/Shared/_LayoutPCA.cshtml";
  6. }
  7. else
  8. {
  9. Layout = "~/Views/Shared/_Layout.cshtml";
  10. }
  11.  
  12. }

Report this snippet  

You need to login to post a comment.