title: ASP.NET MVC partial rendering issue using Razor
body: <p>I have <strong>_Layout.cshtml</strong> defined for my mvc application, which is shown below:</p>
  
  <pre><code>@inherits System.Web.Mvc.WebViewPage
  @using Webdiyer.WebControls.Mvc;
  
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;   
      @RenderSection("HeaderContent", false)
  &lt;/head&gt;
  
  &lt;body&gt; 
      @RenderBody() 
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>On the page <strong>SomePage.cshtml</strong>, I have included the layout, and also included the partial rendering construction, because I want my <strong>_MailForm.cshtml</strong> to be rendered on this page:</p>
  
  <pre><code>@{
     View.Title = "page";
     Layout = "~/Views/Shared/_Layout.cshtml";
  }
  
  @Html.Partial("_MailForm")
  </code></pre>
  
  <p>My <strong>_MailForm.cshtml</strong> file looks following:</p>
  
  <pre><code>@inherits System.Web.Mvc.WebViewPage&lt;CMS.Models.Mail.MailModel&gt;
  
  @section HeaderContent
  {
      &lt;script src="@Url.Content("~/Scripts/mail.js")" type="text/javascript"&gt;&lt;/script&gt;
  }
  
  &lt;form&gt;...&lt;/form&gt;
  </code></pre>
  
  <p>The <strong>HeaderContent</strong> section declared in <strong>_MailForm.cshtml</strong>, suppose to be rendered from <strong>_Layout.cshtml</strong> and load <strong>mail.js</strong> script. The script is actually <strong>not</strong> loaded and because of that my form logic is not working. If I move that <strong>HeaderContent</strong> section from <strong>_MailForm.cshtml</strong> to <strong>SomePage.cshtml</strong>, everything works because mvc loads the script.</p>
  
  <p>But how to load that script from inside <strong>_MailForm.cshtml</strong> file?</p>
  
  <p>Regards</p>