Load different layout page based on controller


/ Published in: C#
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.