title: How to use "RenderBody()" in partial view when the partial view is shared across layout pages?
body: <p>Following is the exact scenario in my ASP.NET MVC application:</p>
  
  <p>There are two layout pages which are quite identical to each other. But one is having angular related attributes in "" tag, whereas other is a non-angular layout. In order to avoid duplicate markup in both razor layout files, I thought to create a partial view and share it across the layout pages. </p>
  
  <p>Following is the partial view (razor), I have named it as "_LayoutPartial":</p>
  
  <p><strong>_LayoutPartial.cshtml</strong></p>
  
  <pre><code>&lt;div class="navbar navbar-inverse navbar-fixed-top"&gt;
      &lt;div class="container"&gt;
          &lt;div class="navbar-header"&gt;
              &lt;button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"&gt;
                  &lt;span class="icon-bar"&gt;&lt;/span&gt;
                  &lt;span class="icon-bar"&gt;&lt;/span&gt;
                  &lt;span class="icon-bar"&gt;&lt;/span&gt;
              &lt;/button&gt;
              @Html.ActionLink("Application name", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
          &lt;/div&gt;
          &lt;div class="navbar-collapse collapse"&gt;
              &lt;ul class="nav navbar-nav"&gt;
                  &lt;li&gt;@Html.ActionLink("Home", "Index", "Home")&lt;/li&gt;
                  &lt;li&gt;@Html.ActionLink("About", "About", "Home")&lt;/li&gt;
                  &lt;li&gt;@Html.ActionLink("Contact", "Contact", "Home")&lt;/li&gt;
              &lt;/ul&gt;
              @Html.Partial("_LoginPartial")
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="container body-content"&gt;
      @RenderBody()
      &lt;hr /&gt;
      &lt;footer&gt;
          &lt;p&gt;&amp;copy; @DateTime.Now.Year - My ASP.NET Application&lt;/p&gt;
      &lt;/footer&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>The above partial view is shared in "_Layout.cshtml", and "_AngularLayout.cshtml" which are as per below:</p>
  
  <p><strong>_Layout.cshtml</strong></p>
  
  <pre><code>&lt;body&gt;
      @Html.Partial("_LayoutPartial")
  
      @Scripts.Render("~/bundles/jquery")
      @Scripts.Render("~/bundles/bootstrap")
      @RenderSection("scripts", required: false)
  &lt;/body&gt;
  </code></pre>
  
  <p><strong>_AngularLayout.cshtml</strong></p>
  
  <pre><code>&lt;body ng-app="myAngularLab"&gt;
      @Html.Partial("_LayoutPartial")
  
      @Scripts.Render("~/bundles/jquery")
      @Scripts.Render("~/bundles/bootstrap")
      @RenderSection("scripts", required: false)
  &lt;/body&gt;
  </code></pre>
  
  <p>When I try to run the MVC application, I get following error:</p>
  
  <blockquote>
    <p>The file "~/Views/Shared/_LayoutPartial.cshtml" cannot be requested
    directly because it calls the "RenderBody" method.</p>
  </blockquote>
  
  <p>The error message is very obvious, and it seems that we can use RenderBody method only in the master page, and not anywhere else. But I am keen to know how we can have two identical layout pages (with a little differences as shown in the example) by writing common code instead of keeping duplicate code in both layout pages?</p>