Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could put a <code>_ViewStart.cshtml</code> file inside the <code>/Views/Public</code> folder which would override the default one in the <code>/Views</code> folder and specify the desired layout:</p> <pre><code>@{ Layout = "~/Views/Shared/_PublicLayout.cshtml"; } </code></pre> <p>By analogy you could put another <code>_ViewStart.cshtml</code> file inside the <code>/Views/Staff</code> folder with:</p> <pre><code>@{ Layout = "~/Views/Shared/_StaffLayout.cshtml"; } </code></pre> <p>You could also specify which layout should be used when returning a view inside a controller action but that's per action:</p> <pre><code>return View("Index", "~/Views/Shared/_StaffLayout.cshtml", someViewModel); </code></pre> <p>Yet another possibility is a custom action filter which would override the layout. As you can see many possibilities to achieve this. Up to you to choose which one fits best in your scenario.</p> <hr> <p>UPDATE:</p> <p>As requested in the comments section here's an example of an action filter which would choose a master page:</p> <pre><code>public class LayoutInjecterAttribute : ActionFilterAttribute { private readonly string _masterName; public LayoutInjecterAttribute(string masterName) { _masterName = masterName; } public override void OnActionExecuted(ActionExecutedContext filterContext) { base.OnActionExecuted(filterContext); var result = filterContext.Result as ViewResult; if (result != null) { result.MasterName = _masterName; } } } </code></pre> <p>and then decorate a controller or an action with this custom attribute specifying the layout you want:</p> <pre><code>[LayoutInjecter("_PublicLayout")] public ActionResult Index() { return View(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload