简体   繁体   English

应该查看渲染菜单或母版页

[英]Should view render menus or master pages

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. 我已经开发使用ActiveRecord自己的自定义用户和角色的对象不扩展默认Asp.Net供应商,因此,我无法摆脱的HttpContext用户。 I can create a custom htmlhelper to render menus but should my views render the menu or the master page? 我可以创建自定义的HtmlHelper渲染菜单而应我的看法呈现菜单或母版页?

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. 如果是母版页,由于某些菜单项取决于用户角色,我该如何将自定义htmlhelper之类的内容传递给当前用户。

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. 1)如果菜单功能应该存在于多个页面上,则将其放在母版页中是有意义的。 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. 2)一个流行的选择是使所有ViewModel都从基视图类继承,然后您的母版页将使用它。 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. 3)您可以从路径数据中拔出特定的控制器。 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. 通常,所有ASP.NET控件(无论是WebForms还是MVC)都应控制自己的状态。

In the case of handling navigation, I'd say create a .ASCX (partial view) and place it on your master page. 在处理导航的情况下,我想创建一个.ASCX(部分视图)并将其放在您的母版页上。 Let the partial view control how it is displayed based on the HttpContext. 让部分视图控制如何基于HttpContext显示它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM