tags:

views:

566

answers:

4

Hi, here's what I'm trying to do :

On a page, I would have a LeftMenu that would be independent of the page, and a RightMenu that would depend on the page the user is currently on.

I want to use MVC from asp.net. I could use RenderPartial to render the menus but on the other hand, the View shouldn't really handle this - so it seems to me that I'm thinking more WinForms than MVC.

Plus the RightMenu would have to know a little bit about what is displayed currently in order to display the correct menu items based on context.

How would you handle this situation. Also any links that talk about this would be greatly appreciated.

EDIT When I said that the View shouldn't handle this I was thinking of RenderPartial in every view and that was kinda nasty - I guess the masterpage approach and then every controller putting something in the ViewModel so that the RightMenu would know what to render might be what I'm looking for .

+1  A: 

Your best bet would be to put the menu in a master page and assign that master page to whatever views require the menu.

Chris
That would probably work for the left menu, but the RightMenu would need contextual information to know what to display. I guess every controller could place something in the ViewModel to give that context but it feels ....... not quite ok
sirrocco
sub-masters is how I would do the contextual menu assuming the context is per subsection of the site rather than per page
Garry Shutler
What exactly should be in the right menu? If it are just links and titles, you can have these added in a dedicated field in your viewData by the controllers.
borisCallens
Sub-masters? Why not just have a content placeholder structure in the main master for the right menu and let each view either render it's own menu in the placeholder or leave it empty? In the case of a shared menu where the contextual info is which item should be selected, this is one viewdata item.
Chris
A: 

Assume a tiles like framework where you could separate Left side which has menu and the Right side is body.So when ever you create a template use right side part from inserting the page which is independently loaded.you can look for [http://tiles.apache.org/index.html][1]

GustlyWind
A: 

For the left menu, put it in the Master Page and use a partial (user control for it).

For the right menu, look at using the RenderAction HtmlHelper extension. This allows the partial view to spin up its own controller and return ViewData independent of the main view's controller. Additionally, you can pass data from the main view page's ViewData to the action method to customize the data to be displayed.

Matthew
+1  A: 

In the early days of the MVC CTP, we discussed this at length.

I don't believe that the controller should be stuffing all kinds of somewhat unrelated data (to its task), into the ViewModel to drive a menu.

One of the early proposals was to just use AJAX to call a different action on the controller to get menu data, I think that was horrible.

I haven't been working with MVC much since the CTP, but I believe a compromise was developed called RenderAction, which allows a View (or a master page) to call to a controller and spawn a partial view.

This an area where the idea of MVC really breaks down, because you start getting too much logic in your view.

FlySwat
This is was my question :). If the view knows to render another view then it gets complicated. But maybe with a masterpage ... it's a reasonable compromise. Although the controller action will have to set something in ViewModel, so the view knows what to render.
sirrocco