title: MVC executing view code before layout code and ruining my script order
body: <p>I'm trying to move all of my javascript includes to the bottom of the page.  I'm using MVC with Razor.  I've written a helper method to register scripts. It keeps the scripts in the order they're registered and it excludes dupes.  </p>
  
  <pre><code>@{ Html.RegisterScript("/scripts/someFile.js"); }
  </code></pre>
  
  <p>And then right before the closing body tag I do something like this:</p>
  
  <pre><code>    @Html.RenderScripts()
  &lt;/body&gt;
  </code></pre>
  
  <p>This all works fine if the scripts are registered all on one page.  If I register some scripts in my layout, and some scripts in my inner view, things go awry.  Basically, the inner view is executing before the layout. So event though the scripts in the inner view depend on the scripts in the outer view, they're being registered prior.</p>
  
  <p>So if I have _Master.cshstml and it has</p>
  
  <pre><code>@{
     Html.RegisterScript("script1.js");
     Html.RegisterScript("script2.js");
  }
  </code></pre>
  
  <p>And then I have InnerView.cshtml with _Master.cshtml as its layout and in the view I have</p>
  
  <pre><code>@{
     Html.RegisterScript("script3.js");
  }
  </code></pre>
  
  <p>The scripts get rendered out in this order: script3, script1, script 2.</p>
  
  <p>Is there any way I can force the layout to execute before the inner view?  I've tried moving things all over the place and everything the inner view always seems to execute first.  Perhaps this is expected?  If so, what is the best way for me to accomplish what I'm trying to do?</p>