title: How can I set up conditional Layouts with _ViewStart in ASP.NET Core Razor Pages?
body: <p>I want to display different layouts based on the current rendered Page.</p>
  
  <p>I can't find anything online about this but I feel like this should be an extremely common use case.</p>
  
  <p>I only have a few pages. I would like to assign unique layouts to both my Register and Login pages.</p>
  
  <p>This is what I've got so far but I am unable to use the ControllerContext in this situation.</p>
  
  <pre><code>@{
      string controllerName = this.ControllerContext.RouteData.Values["controller"].ToString();
      dynamic Layout;
      switch (controllerName)
      {
          case "Register":
              Layout = "_RegisterLayout";
              break;
          case "Login":
              Layout = "_LoginLayout";
              break;
          default:
              Layout = "_Layout";
              break;
      }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/Y6ozH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Y6ozH.png" alt="enter image description here"></a></p>