title: ASP.NET MVC 3, sections and multiple layout levels
body: <p>I can't find a way to make @section and @RenderSection() work with multiple level layouts. In my project I define a hierarchy of layouts:</p>
  
  <p>~/Views/Shared/_Layout.cshtml:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta ... /&gt;
      &lt;meta ... /&gt;
  
      &lt;link href="..." rel="stylesheet" type="text/css" /&gt;
      &lt;link href="..." rel="stylesheet" type="text/css" /&gt;
  
      @RenderSection("Stylesheet", false)
  &lt;/head&gt;
  &lt;body&gt;
      &lt;!-- lots of markup --&gt;
      @RenderBody()
  
      &lt;!-- more markup --&gt;
  
      &lt;script src="..." type="text/javascript" /&gt;
      &lt;script src="..." type="text/javascript" /&gt;
  
      @RenderSection("JavaScript", false)
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>~/Views/Shared/_BaseLayout.cshtml (there are no definitions of JavaScript or Stylesheet sections):</p>
  
  <pre><code>@{
      Layout = "~/Views/Shared/_Layout.cshtml";
  }
  
  &lt;!-- lots of markup --&gt;
  @RenderBody()
  </code></pre>
  
  <p>~/Views/Shared/_CreateEditLayout.cshtml (again, no definitions of JavaScript or Stylesheet):</p>
  
  <pre><code>@{
      Layout = "~/Views/Shared/_Layout.cshtml";
  }
  
  &lt;!-- lots of markup --&gt;
  @RenderBody()
  </code></pre>
  
  <p>~Views/Profile/Edit.cshtml:</p>
  
  <pre><code>@model ...
  
  @{
      Layout = "~/Views/Shared/_CreateEditLayout.cshtml";
  }
  
  @section JavaScript {
      &lt;script type="text/javascript"&gt;
          jQuery(document).ready(function ($) {
              // lots of funny JS
          });
      &lt;/script&gt;
  }
  </code></pre>
  
  <p>My problem is that it is enough to just define <code>@section JavaScript { }</code> (it isn't necessary to write markup or JavaScript inside the section) for my <code>Edit.cshtml</code> stop been rendered. The error is the following: The following sections have been defined but have not been rendered for the layout page "~/Views/Shared/_CreateEditLayout.cshtml": "JavaScript".</p>
  
  <p>Any ideas what is going wrong? Thanks in advance.</p>