title: asp.net mvc2 - controller for master page and code organization
body: <p>I've just finished my first ASP.NET MVC (2) CMS. Next step is to build website that will show data from CMS's database. This is website design:</p>
  
  <p><a href="http://img56.imageshack.us/img56/4676/portal.gif" rel="nofollow noreferrer">http://img56.imageshack.us/img56/4676/portal.gif http://img56.imageshack.us/img56/4676/portal.gif</a></p>
  
  <p><br>
  <strong>#1 (Red box)</strong> - displays article categories. ViewModel:<br></p>
  
  <pre><code>public class CategoriesDisplay
      {
          public CategoriesDisplay() { }
  
          public int CategoryID { set; get; }
          public string CategoryTitle { set; get; }
      }
  </code></pre>
  
  <p><strong>#2 (Brown box)</strong> - displays last x articles; skips those from green box #3. Viewmodel:<br></p>
  
  <pre><code>public class ArticleDisplay
      {
          public ArticleDisplay() { }
  
          public int CategoryID { set; get; }
          public string CategoryTitle { set; get; }
  
          public int ArticleID { set; get; }
  
          public string ArticleTitle { set; get; }
          public string URLArticleTitle { set; get; }
          public DateTime ArticleDate;
  
          public string ArticleContent { set; get; }
  
      }
  </code></pre>
  
  <p><strong>#3 (green box)</strong> - Displays last x articles. Uses the same ViewModel as brown box #2<br></p>
  
  <p><strong>#4 (blue box)</strong> - Displays list of upcoming events. Uses <code>dataContext.Model.Event</code> as ViewModel</p>
  
  <p>Boxes #1, #2 and #4 will repeat all over the site and they are part of Master Page. So, my question is: what is the best way to transfer this data from Model to Controller and finally to View pages?</p>
  
  <ol>
  <li>Should I make a controller for
  master page and ViewModel class that will wrap all this classes together OR</li>
  <li>Should I create partial Views for
  every of these boxes and make each
  of them inherit appropriate class
  (if it is even possible that it
  works this way?) OR</li>
  <li>Should I put this repeated code in
  all controllers and all additional
  data transfer via ViewData, which
  would be probably the worse way :) OR</li>
  <li>There is maybe a better and more
  simple way but I don't know/see it?</li>
  </ol>
  
  <p><br>
  Thanks in advance,
  Ile</p>
  
  <p><br><br>
  <strong>EDIT:</strong><br>
  If your answer is #1, then please explain how to make a controller for master page!
  <br>
  <br>
  <strong>EDIT 2:</strong><br>
  In this tutorial is described how to pass data to master page using abstract class: <a href="http://www.asp.net/LEARN/mvc/tutorial-13-cs.aspx" rel="nofollow noreferrer">http://www.asp.net/LEARN/mvc/tutorial-13-cs.aspx</a><br>
  In "Listing 5 – Controllers\MoviesController.cs", data is retrieved directly from database using LINQ, not from repository. So, I wonder if this is just in this tutorial, or there is some trick here and repository can't/shouldn't be used?</p>