在asp.net应用程序活动类Twitter的引导的导航? [英] Twitter bootstrap nav in asp.net application active class?
问题描述
我使用在asp.net应用程序Twitter的引导和下面是我的code的导航栏:
I am using Twitter bootstrap in an asp.net application and below is my code for the navbar:
<div class="navbar">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="../">MyApp</a>
<ul class="nav">
<li class="active"><a href="../">Home</a></li>
<li><a href="../About.aspx">About us</a></li>
<li><a href="../ContactUs.aspx">Contact us</a></li>
</ul>
</div>
</div>
</div>
我想每一个我一个链接到菜单页面上的时间来改变活动的菜单项。我该怎么做呢?
I would like to change the active menu item each time I am on a page that links to the menu item. How do I do this?
推荐答案
@Toby琼斯的确暗示的好帮手方法。不过,有些人可能只需要选择由控制器和其他菜单项可能希望得到由控制器和行动的组合来选择菜单项。由托比提到的文章中提到的解决方案只需要第二个方案的护理。
@Toby Jones indeed suggests a good helper method. However, some people might want to select menu items only by Controller and others might want to get menu items selected by the combination of a controller and action. The solution mentioned in the article referred by Toby only takes care of the second scenario.
TwitterBootstrapMvc 涵盖这两种情况下使用的语法如下:
Library TwitterBootstrapMvc covers both situations with the following syntax:
@using (var nav = Html.Bootstrap().Begin(new Nav().SetLinksActiveByControllerAndAction()))
{
@nav.ActionLink("Link 1", MVC.Account.SomeAction())
@nav.ActionLink("Link 2", "SomeOtherAction")
}
Mthod .SetLinksActiveByControllerAndAction()
可以用方法来代替 .SetLinksActiveByController()
这将为第一个方案工作
Mthod .SetLinksActiveByControllerAndAction()
could be replaced by method .SetLinksActiveByController()
which would work for the first scenario.
另外,值得一提的是,同样的扩展方法可在下拉菜单:
It is also worth mentioning that the same extension methods are available on DropDowns:
@using (var dd = Html.Bootstrap().Begin(new DropDown("Some Trigger").SetLinksActiveByController()))
{
@dd.ActionLink("Some link", "action")
}
这篇关于在asp.net应用程序活动类Twitter的引导的导航?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!