title: how to manage logic in the _Layout.cshtml
body: <p>I am currently working with an mvc site where I have a fairly extensive main layout page. It is dependent on data from the database which in turns includes inherent logic as what to include etc on the layout.</p>
  
  <p>Most of my controller actions are rendered within this layout. I am not sure of how to work this. Being used to master pages in web forms, all the logic resides in the master page. I have a couple mechanisms to achieve the common layout logic but looking for the best practise way of achieving such.</p>
  
  <p>Options are:</p>
  
  <ul>
  <li>Replicate logic in all controller actions (not really an option)</li>
  <li>Extract the logic in to another class and call it from the controller actions</li>
  <li>All controllers inherit from a base controller which as overrides the OnActionExecuting method and us this to perform logic and return the necessary data in the TempData</li>
  <li>Use "RenderAction" in the cshtml to call necessary controller actions and extract the layout in to smaller partial views</li>
  </ul>
  
  <p>Any other options open to me or recommendations?</p>