title: Setting the Body's OnLoad attribute in an Asp.net MVC Master Page
body: <p>I have a view using a master page that contains some javascript that needs to be executed using the OnLoad of the Body. What is the best way to set the OnLoad on my MasterPage only for certain views?</p>
  
  <p>On idea I tried was to pass the name of the javascript function as ViewData. But I dont really want my Controllers to have to know about the javascript on the page. I really don't like this approach...</p>
  
  <pre><code>&lt;body onload="&lt;%=ViewData["Body_OnLoad"]%&gt;"&gt;
  &lt;asp:ContentPlaceHolder ID="MainContent" runat="server" /&gt;
  </code></pre>
  
  <p>Edit - I suppose one idea would be to use jQuery's document ready event instead...</p>
  
  <p>Any other ideas?</p>