开发者

Should view render menus or master pages

开发者 https://www.devze.com 2023-01-02 23:24 出处:网络
I\'ve developed my own custom users and role开发者_如何学Pythons objects using ActiveRecord that do NOT extend the default Asp.Net providers and therefore I can\'t get the user from the HttpContext. I

I've developed my own custom users and role开发者_如何学Pythons 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) 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消