MVC 3 中突出显示菜单和子菜单?
我正在尝试创建一个突出显示当前页面的菜单。我在这里找到了一些答案,但问题是我看不到有人处理子菜单。
这里有一个看起来非常简单的答案: 活动菜单项 - asp. net mvc3 母版页
但据我所知,如果您单击子菜单,该母版页将仅突出显示子菜单项。我希望突出显示子菜单项及其顶部菜单中的父菜单项。
例如,如果有人单击“服务”,然后单击“咨询”,我希望这两个按钮都突出显示 - 顶部菜单中的“服务”和子菜单中的“咨询”。我该怎么做?
顺便说一句,我希望能够使用 CSS 将子菜单呈现为下拉菜单,也可以呈现为侧边栏。如何获取子菜单 ul 并将其呈现为侧边栏?
I am trying to create a menu that highlights the current page. I have found a few answers here, but the problem is I can't see that anyone handles submenus.
There is an answer here that looks enticingly simple: active menu item - asp.net mvc3 master page
But as far as I can tell, that one will highlight only the sub menu item if you click on a submenu. I want the submenu item to be highlighted, as well as its parent in the top menu.
E.g. if someone clicks Services, and then Consulting, I would want both of these to be highlighted - Services in the top menu, and Consulting in the submenu. How can I do this?
BTW, I would like to be able to render the submenu both as a dropdown using CSS, and also as a sidebar. How can I take the submenu ul and render it as a sidebar?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是一个简单的东西,你可以根据你的需要修改它,但基础知识就在这里。
http://developerstyle.posterous.com/highlighting-current -page-in-mvc-3-slick-tric
上面的链接可能会在Posterous关闭后立即关闭,这是一个更新链接
http://bhavinsurela.com/highlighting-current-page- in-mvc-3-slick-tric/
Here is a simple thing, you can modify it according to your needs but basics are here.
http://developerstyle.posterous.com/highlighting-current-page-in-mvc-3-slick-tric
This above link might be down soon as posterous is closing, here is an update link
http://bhavinsurela.com/highlighting-current-page-in-mvc-3-slick-tric/
我有一个解决方案,我在 SO 中也找到了部分解决方案并进行了修改,但仍有待改进,以便处理任意数量的子菜单......现在它适用于子菜单。
ViewModel
视图
CSS 我现在正在使用它:
I have a solution which I in part also found here in SO and modified, but still as to be improved in order to handle any number of submenus... right now it works for a submenu.
The ViewModel
The View
The CSS I'm using with this at the moment:
只需使用 ViewContext.RouteData.Values 字典(特别是 Action 和 Controller 键)即可非常简单地确定要突出显示的菜单元素。
这是一个快速帮助方法:
并且可以从这样的视图中使用:
由于我不熟悉您的应用程序结构,因此很难进入更具体的解决方案,但这应该会给您一个开始的想法。
It's fairly simple to determine which menu element to highlight by simply using the
ViewContext.RouteData.Values
dictionary, specifically theAction
andController
keys.Here's a quick helper method :
And can be used from the view as such :
It's hard to get into a more specific solution as I'm not familiar with your application structure, but this should give you an idea to get started.
这是一个处理子菜单并突出显示它的示例。
http://users.tpg.com.au/j_birch/plugins/superfish/ #sample4
它使用 superfish-navbar.css,您可以在其中看到它是如何完成的。
这是一个非常好的菜单插件。
Here is a example where they handle the submenus and highlight it.
http://users.tpg.com.au/j_birch/plugins/superfish/#sample4
It uses superfish-navbar.css where you can see how it is done.
It is a very good plugin for menus.