views:

36

answers:

2

I've developed my own custom users and roles objects using ActiveRecord that do NOT extend the default Asp.Net providers and therefore I can't get the user from the HttpContext. I can create a custom htmlhelper to render menus but should my views render the menu or the master page?

If it's the master page how can I pass to the custom htmlhelper things like current user since some menu items depend on the user roles.

Also, how can I detect what controller is being viewed inside my master pages?

+1  A: 

In general, all ASP.NET controls (whether WebForms or MVC) should control their own state.

In the case of handling navigation, I'd say create a .ASCX (partial view) and place it on your master page. Let the partial view control how it is displayed based on the HttpContext.

JMP
Thanks for that. I did end up creating a partial view which will take care of rendering my menus. Its very sweet.
Am
+2  A: 

1) If your menu functionality is supposed to exist on multiple pages, then it makes sense to put it in the master page. If not, then the normal view.

2) A popular choice is to make all of your ViewModels inherit from a base view class, and then your Master page uses that. Example:

System.Web.Mvc.ViewMasterPage<ViewBase>
System.Web.Mvc.ViewPage<MyViewModel>

public class MyViewModel : ViewBase { }

3) You can pull out the specific controller from the route data. However, if you need specific functionality for certain controllers, I would just suggest using a different master page for those views than trying to make all of your views use the same master page.

Tejs
Your suggestion worked well because it forced me to go with completely strong typed view models for all my views.
Am