1 public static class MvcHtmlExtension
2 {
3 public static MvcHtmlString MenuLink(this HtmlHelper helper, string text, string action, string controller)
4 {
5 var routeData = helper.ViewContext.RouteData.Values;
6 var currentCOntroller= routeData["controller"];
7 var currentAction = routeData["action"];
8 if (String.Equals(action, currentAction as string, StringComparison.OrdinalIgnoreCase) &&
9 String.Equals(controller, currentController as string, StringComparison.OrdinalIgnoreCase))
10 {
11 return helper.ActionLink(text, action, controller, null, new { @class = "menua" });
12 }
13 return helper.ActionLink(text, action, controller);
14 }
15 }
1 <div class="collapse navbar-collapse pull-right">
2 <ul class="nav navbar-nav">
3 <li>@Html.MenuLink("育儿宝典", "YuErBaoDian", "Home")li>
4 <li>@Html.MenuLink("关于我们", "About", "Home")li>
5 <li>@Html.MenuLink("联系我们", "Contact", "Home")li>
6 ul>
7 div>