views:

327

answers:

3

Hi,

I am envisioning a site layout like this-

top navigation menu linking to maybe 4 or 5 indexes of different controllers. each of these sections will be working with different model objects.

Left navigation menu is specific to a controller. so, for each of the top menu buttons (corresponding to different controllers) I would like the left navigation menu to offer options only specific to the currently used controler.

What's the best way to go about setting this up?

Thanks!!

A: 

Have separate master pages for the views for each controller/category is a possibility, where the specific menu is defined it the master page.

Are these menus static?

curtisk
nope- both the top and left navigation are driven off of user's roles
jj
A: 

It sounds like the different controllers is the right way to go for your top menu given that you've stated each controller would be working with different model objects (which I take to mean different logical divisions). It makes sense to break logical chunks of your database/models into separate controllers.

As far as the left navigation menu, you could simply use different actions on the controller to service that section where it makes sense. Just think of actions as exactly that... actions.

You could think of StackOverflow itself as following a similar pattern, where there are 5 (or so) controllers along the top of the page, and then there are actions on those controllers. For example the "users" controller has actions for registering a new account, viewing user details, searching for existing users, etc. This is a common pattern in the ASP.NET MVC sites I've seen, and ASP.NET MVC itself is geared toward this type of a scenario.

I'm not really sure there's much else to say, but if you have more specific questions, feel free to post them. I think you're on the right track, though. Good luck.

Scott Anderson
thanks-what I am not clear on, though, is how i would 'create' the left nav based on the controller. it can't be strongly typed since different users might have access to different 'actions', via roles.
jj
Why not? To me you could make partial views for each role under the controller and then render the partial that matches the role.
Scott Anderson
Check here if you need an example of what I'm talking about: http://stackoverflow.com/questions/409213/how-can-i-create-a-view-that-has-different-displays-according-to-the-role-the-use/409303#409303
Scott Anderson
A: 

I use custom attribute for this:

[LeftMenu("MyMenu")]
public class MyController ...

In my base controller, OnActionExecuted checks for the attribute, and use reflection to invoke CustomMenus.Get{menuname}(). Then it sets ViewData["leftmenu"]. You can avoid custom attribute if you just use controller's name as menu name.

CustomMenus is a class whose methods return IList<IMenuItem> - but that's my own menu system, you may decide to return classes, partial names, whatever suites your menu system.

queen3