views:

561

answers:

2

hello

I want to have 2 navigation menus- One will be a "Top Level" menu, with 4 choices, each pointing to the index of a separate controller.

I would like to have a "Controller-Level" sub-menu on the left of my screen. This will correspond to links relevant to the controller selected in the top menu.

The "controller-level" menu is not static and needs to be customized based on roles of user.

The top-level one is basic. But how can i create the second menu that will change when a controller is selected from top?

danke!

A: 

If you are using MVC 2 RC or MVC Futures, then use RenderAction.

Create a controller for the dynamic menu, and call RenderAction("action", "controller"). This will invoke the controller, and you can have your logic in the controller to show the correct menu.

Martin
thanks! so, i'd call RenderAction("displayMenu1", "MenuController") from the constructor of Controller 1, RenderAction("displayMenu2", MenuController") from the constructor of Controller 2? Where is the proper place to make the RenderAction() call?
zz robert
You call the render action where you want the action to be rendered (in the view).
Mattias Jakobsson
oh. that doesn't sound like it can go in a master page, then. but i'd like to not have to call "renderaction" for the left navigation menu on every single view.
zz robert
hm maybe i can put the controller name in the viewdata, and render the menu like Html.RenderAction(ViewData["CurrentController"], "MenuController")
zz robert
That isn't relay good practice and will probably cause some problems later on. If you can't consider writing one extra line of code in your views you should just use nested master pages.
Mattias Jakobsson
my site's controllers will be rendering maybe 15-20 views each. it seems tedious and inefficient to put "RenderAction("appropriateMenuForThisController", "MenuController")" in each of my views, for maybe up to 100x
zz robert
Then use nested master pages.
Mattias Jakobsson
i appreciate your help on this.
zz robert
Or put a content placeholder in the master page, then fill it with the proper RenderAction() call in each view.
Pawel Krakowiak
A: 

I'm working on a similar situation where I need two menus. Was a "best-practice" ever resolved here? I have the need for one menu on the left, and a dynamically created tab-like menu at the top depending on what page I'm working with/on.

The user actually needs the ability to add/remove/hide top tabs depending on preferences. We are using MVC 2 and I'm not sure if the tab bar belongs in a control, on individual views, or what...and also how to make them both interact with my pages. (The left nav needs to show where the user is at all times, and the top tab needs to be highlighted based on the sub-page the user has selected.

Newbie