title: How to intercept view rendering to add HTML/JS on all partial views?
body: <p>I need to write the contents of a js file from a convention-driven location (like ~/ClientApp/Controllers/Home/Home.js if loading the view located at ~/Views/Home/Home.cshtml). How do I do this?</p>
  
  <p>Example: if the file ~/Views/Home/Home.cshtml looks like:</p>
  
  <pre><code>&lt;div id="some-partial-view"&gt;
     &lt;!-- ... --&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>And the file ~/ClientApp/Controllers/Home/Home.Controller.js looks like</p>
  
  <pre><code>function HomeController() {
    //some code
  }
  </code></pre>
  
  <p>Then the rendered view returned by the webserver should look like (if using fiddler)</p>
  
  <pre><code>&lt;!--ommitted &lt;html&gt; &lt;body&gt; tags --&gt;
  
  &lt;div id="some-partial-view"&gt;
     &lt;!-- ... --&gt;
  &lt;/div&gt;
  
  &lt;script type="text/javascript"&gt;
     function HomeController() {
         //some code
     }
  &lt;/script&gt;
  </code></pre>
  
  <p>One way is to add an HTML Helper that will do this such as:</p>
  
  <pre><code>&lt;div id="some-partial-view" ng:Controller="HomeController"&gt;
     &lt;!-- ... --&gt;
  &lt;/div&gt;
  @Html.IncludeController("HomeController") 
  </code></pre>
  
  <p>However, i don't want to repeat this in all partial views.</p>
  
  <p>Any ideas?</p>