title: @RenderSection in nested razor templates
body: <p>My problem is I can't seem to use <code>@RenderSection</code> from a nested template when <code>@RenderSection</code> is defined in the base template.  Currently, I have a nested base template which is linked to a child template which is then used in the view pages.  When I define the <code>@RenderSection</code> in the base template and render it in the view pages it throws an error.</p>
  
  <p>Here's the exact problem.</p>
  
  <p>I want to create a RenderSection to allow me to insert custom scripts.
  My base template.... </p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;@ViewBag.Title&lt;/title&gt;
   @RenderSection("HeaderContent", false) // The region of the header scripts (custom css)
  
  &lt;/head&gt;
  &lt;body&gt;
  @RenderBody()
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I then skip the child template as I do not want to put any custom head code in there and apply it to the page itself..</p>
  
  <pre><code>@section HeaderContent {
      &lt;script&gt;alert("hi");&lt;/script&gt;
  }
  </code></pre>
  
  <p>My problem is that I cant seem to add custom head code in to the base template from my normal pages.</p>
  
  <p>The following sections have been defined but have not been rendered for the layout page <code>~/Views/Shared/OneColLayer.cshtml": "HeaderContent</code>.</p>
  
  <p>Do I need to include a pointer to the base template in the view page?</p>
  
  <pre><code>@{
      Layout = "~/Views/Shared/BaseTemplate.cshtml";
  }
  </code></pre>
  
  <p>My new base template</p>
  
  <pre><code>&lt;head&gt;
    &lt;link rel="stylesheet" type="text/css" href="@Url.Content("~/content/layout.css")" /&gt;
    &lt;link rel="stylesheet" type="text/css" href="@Url.Content("~/content/global.css")" /&gt;
    &lt;script type="text/javascript" src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")"&gt;&lt;/script&gt;
    &lt;script type="text/javascript" src="@Url.Content("~/js/fadeInFadeOut.js")"&gt;&lt;/script&gt;
    &lt;title&gt;@ViewBag.Title&lt;/title&gt;
    @RenderSection("HeaderContent", false)
  &lt;/head&gt;
  &lt;body&gt;
    @RenderBody()
  &lt;/body&gt;
  </code></pre>
  
  <p>my new child template</p>
  
  <pre><code>@{
    Layout = "~/Views/Shared/BaseTemplate.cshtml";
  }
  @RenderSection("HeaderContent", false)
  @RenderBody()
  </code></pre>
  
  <p>my view</p>
  
  <pre><code>@{
    ViewBag.Title = "Home";
    Layout = "~/Views/Shared/OneColLayer.cshtml";
  }
  @section HeaderContent {
    &lt;h1&gt;Left Content&lt;/h1&gt;
  }
  &lt;div&gt;my view content&lt;/div&gt;
  </code></pre>
  
  <p>the content gets placed in the oneCol template now the base template.</p>
  
  <p>results...</p>
  
  <pre><code>&lt;div id="Content"&gt;
     &lt;h1&gt;Left Content&lt;/h1&gt;
  &lt;/div&gt;
  </code></pre>