title: Ordering loading of Actions in ASP.NET MVC View
body: <p>In _Layout.cshtml we're using a PartialView for the sidebar, like this:</p>
  
  <pre><code>        @{ 
              var menuSideAction = Url.Action(MVC.Common.MenuSide());
          }
          &lt;div ng-include="'@menuSideAction'"&gt;
  
          &lt;/div&gt;
  </code></pre>
  
  <p>The controller method is just this:</p>
  
  <pre><code>    public virtual ActionResult MenuSide()
      {
          return PartialView("~/Views/Shared/_MenuSide.cshtml");
      }
  </code></pre>
  
  <p>A problem I'm encountering with this approach is that it's not predictable when the Action is executed. Sometimes it loads first when opening the page, sometimes it only loads after the Body is rendered (which for some pages can take some time).</p>
  
  <p>If at all possible I would like to force the page to always load this PartialView first but I haven't found a way to do that.</p>
  
  <h2>UPDATE</h2>
  
  <p>Figured out my problem which I'll post as an answer, turns out I was overthinking (or underthinking if you will) it.</p>
  
  <p>So first, the reason why were using ng-include here is because our AngularJS code on the partial view was not responding without it. Code in the controller was not being triggered.</p>
  
  <p>Prior to the edit to use ng-include, we had a partial HTML page inserted in the _Layout.cshtml like this (simplified):</p>
  
  <pre><code>&lt;body ng-controller="commonController"&gt;
      &lt;div @(ViewBag.AngularController ?? "")&gt;
          &lt;div&gt;
              @Html.Partial("_MenuSide")
          &lt;/div&gt;
          &lt;div&gt;
              @RenderBody()
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>ViewBag.AngularController is set in specific Razor views (for example Address.cshtml would set it to "ng-controller=addressController")</p>
  
  <p>I was expecting code in a "commonController" to be run, as it is set on the  tag. However naturally, the ViewBag.AngularController value would override whatever controller was set on the body. </p>
  
  <p>The fix is to explicitly specify ng-controller again in a div in the partial view and then AngularJS code was working.</p>