title: What is the elegant solution for unrelated views in MVC web frameworks?
body: <p>I've had a problem with the following issue in Rails and ASP.Net MVC.  Often there are multiple widgets of functionality on a page, yet one controller action is supposed to render the page.  Let me illustrate:</p>
  
  <p>Let's say I have a normal e-commerce site, and the menu is made of categories, while the page is to display an group of products.</p>
  
  <p>For the products, let's say I have an action on a controller that looks something like:</p>
  
  <pre><code>def product_list
       @products = Products.find_by_category(:name =&gt; 'lawnmowers')
  end
  </code></pre>
  
  <p>And I have a layout with something like</p>
  
  <pre><code>&lt;div id="menu"&gt;&lt;%= render :partial =&gt; 'menu' %&gt;&lt;/div&gt;
  &lt;div id="content"&gt;&lt;%= yield %&gt;&lt;/div&gt;
  </code></pre>
  
  <p>The products have a view...</p>
  
  <pre><code>&lt;%= render :partial =&gt; 'product', :collection =&gt; @products %&gt;
  </code></pre>
  
  <p><em>(note I've ommited the product view as irrelevant)</em></p>
  
  <p>And the menu has a partial...</p>
  
  <pre><code>&lt;% Category.each {|c| %&gt;
     &lt;%= render :partial =&gt; 'menu_node', :locals =&gt; { :category =&gt; c } %&gt;
  &lt;% } %&gt;
  </code></pre>
  
  <p>The line I have a problem with is the "Category.each.do" in the view.  I'm fetching data in the view, as opposed to using variables that were set and bound in the controller.  And it could easily be a more complex method call that produces the menu.</p>
  
  <p>The solutions I've considered are:</p>
  
  <p>-A view model base class that knows how to get various pieces of data.  But you could end up with one of these for each conceptual "section" of the site.<br>
  -a local variable that populates at the top of each method (violates DRY)
  -the same thing, but in a before_filter call</p>
  
  <p>None of these seem very elegant to me.  I can't help but look at this problem and think that a MVP presenter per view (not screen) is a more elegant solution.</p>
  
  <p>ASP.Net MVC has render action (different from rails render :action), which does address this, but I'm not sure what I think of that solution.  </p>
  
  <p>Thoughts?  Solution suggestions?</p>
  
  <p><strong>Added Note:</strong> 
  The answers provided so far are good suggestions.  And they apply to the example I gave, where a menu is likely present in every layout, and is clearly secondary to the product data.  </p>
  
  <p>However, what if there is clearly no second class citizen?  Portal type sites commonly have multiple unrelated widgets, in which each is important.  </p>
  
  <p>For example, What if this page was displaying weather trends, with widgets for temperature, humidity, and precipitation (and each is a different model and view type).  </p>