title: MVC nested views and partial views
body: <p>I am in the process of creating a prototype project using MVC 3 and I have come across a situation which I can't seem to find an answer for and it seems like I might be approaching the problem the wrong way.</p>
  
  <p>A quick overview of my project; it is based on the MVC template you get with Visual Studio and I use the links (tabs) on the supplied _Layout view to access some of my other views. One of these links opens a second partial view that again contains links for more views (admin specific. hence the split). The problem I am having is that I can't seem to display views with the <code>@RenderBody</code> in the second partial view, which I understand is because you can't have more than one <code>@RenderBody</code> in a completed HTML file, which makes sense.</p>
  
  <p><strong>So my question is, how can I display the views in this manner? Also, probably more importantly, is this the correct way to achieve this 'sub menu' system I am trying for or is there a better way to achieve this?</strong></p>
  
  <p>Here is the relevant parts of the views, first is the 'main' _Layout  file:</p>
  
  <pre><code>&lt;body&gt;
      &lt;div class="page"&gt;
          &lt;header&gt;
              &lt;div id="title"&gt;
                  &lt;h1&gt;Test App&lt;/h1&gt;
              &lt;/div&gt;
              &lt;nav&gt;
                  &lt;ul id="menu"&gt;
                      &lt;li&gt;@Html.ActionLink("Home", "Index", "Home")&lt;/li&gt;
                      @if (User.Identity.IsAuthenticated)
                      {
                          &lt;li&gt;@Html.ActionLink("Contracts", "List", "Contract", new { user=User.Identity.Name, page=1 }, null)&lt;/li&gt;
                      }
                      @if (User.IsInRole("Administrator"))
                      {
                          &lt;li id="admin"&gt;@Html.ActionLink("Administration", "Administration", "Home")&lt;/li&gt;
                      }
                  &lt;/ul&gt;
              &lt;/nav&gt;
          &lt;/header&gt;
          &lt;section id="main"&gt;
              @RenderBody()
          &lt;/section&gt;
          &lt;footer&gt;
          &lt;/footer&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>When clicking the <code>&lt;li id="admin"&gt;@Html.ActionLink("Administration", "Administration", "Home")&lt;/li&gt;</code> link, then the Home controller return the second partial view shown below:</p>
  
  <pre><code>&lt;header&gt;
      &lt;div id="admintitle"&gt;
          &lt;h1&gt;Administration&lt;/h1&gt;
      &lt;/div&gt;  
  &lt;/header&gt;
  &lt;body&gt;
      &lt;div id="div-1a"&gt;
           &lt;nav&gt;
              &lt;ul id="adminmenu"&gt;
                  &lt;li&gt;@Html.ActionLink("Contact", "List", "Contact")&lt;/li&gt;
                  &lt;li&gt;@Html.ActionLink("Home", "Index", "Home")&lt;/li&gt;
              &lt;/ul&gt;
          &lt;/nav&gt;
      &lt;/div&gt;
      &lt;div id="div-1c"&gt;
          &lt;h1&gt;Test&lt;/h1&gt;   
      &lt;/div&gt;
      &lt;section id="adminmain"&gt;
          @RenderBody()
      &lt;/section&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>When I try and run the code, it fails due to the second <code>@RenderBody</code>, which is understandable.</p>
  
  <p>If you need any more information, then please let me know.</p>
  
  <p>Thanks very much.</p>