title: Load Javascript from a Partial View in ASP.NET MVC3
body: <p>I have an ASP.NET MVC3 application in C# and Razor.</p>
  
  <p>I use the standard <code>_Layout.cshtml</code> from the MVC3 application template in VS2010. I would like to add Javascript code in one of my <code>Partial View</code> just when the <code>View</code> is rendered and not attach the Javascript directly in the <code>_Layout</code>.</p>
  
  <p>My <code>View</code> looks like this:</p>
  
  <pre><code>@model MyNameSpace.ViewModels.MyViewModel
  
  @{
      ViewBag.Title = "Home Page";
  }
  
  &lt;h2&gt;@ViewBag.Message&lt;/h2&gt;
  
  @using (Html.BeginForm()) {
      @Html.ValidationSummary(true)
      &lt;fieldset&gt;
          &lt;legend&gt;Filters&lt;/legend&gt;
  
          @{ Html.RenderPartial("Filters", Model.Filters);  }
  
          &lt;p&gt;
              &lt;input type="submit" value="Submit" /&gt;
          &lt;/p&gt;
  
      &lt;/fieldset&gt;
  }
  </code></pre>
  
  <p>And my <code>Partial View</code> <code>Filters.cshtml</code> looks like this:</p>
  
  <pre><code>@model MyNameSpace.ViewModels.FiltersViewModel
  
  &lt;p&gt;
  @Html.DropDownListFor(
      x =&gt; x.Type, 
      new SelectList(Model.Types, "Value", "Text"),
      "-- select type --"
  )
  &lt;/p&gt;
  
  &lt;p&gt;
  @Html.DropDownListFor(
      x =&gt; x.Category, 
      new SelectList(Model.Categories, "Value", "Text"),
      "-- select category --"
  )&lt;/p&gt;
  
  &lt;script type="text/javascript"&gt;
     //Some Javascript
  &lt;/script&gt;
  </code></pre>
  
  <p>If I leave the <code>View</code> like this, the Javascript is rendered inside the <code>&lt;body&gt;</code> and it looks very ugly. I can add the Javascript directly in the <code>&lt;head&gt;</code> section of the _Layout but it is not what I want. How can I achieve my purpose?</p>