我有一个IsActive方法,我可以调用它来根据路由操作/控制器设置活动类。
public static string IsActive(this HtmlHelper htmlHelper, string action, string controller)
{
var routeData = htmlHelper.ViewContext.RouteData;
var routeAction = (string)routeData.Values["action"];
var routeController = (string)routeData.Values["controller"];
var isActive = string.Equals(controller, routeController, StringComparison.InvariantCultureIgnoreCase)
&& string.Equals(action, routeAction, StringComparison.InvariantCultureIgnoreCase);
return isActive ? "active" : null;
}
}
我有一个三级导航,需要在两个位置应用活动类。在实际链接和链接嵌套的菜单上。
<li class="treeview">
<a href="#">
<i class="fa fa-building fa-fw"></i> <span> Company</span> <i class="fa fa-angle-left pull-right"></i>
</a>
<ul class="treeview-menu">
<li class="@Html.IsActive("MAYBEAWILDCARDHERE", "CompanyInformation")">
<a href="#"> Information <i class="fa fa-angle-left pull-right"></i></a>
<ul class="treeview-menu">
<li class="@Html.IsActive("Index", "CompanyInformation")"><a href="@Url.Action("Index", "CompanyInformation")"> Information</a></li>
<li><a href="#"> Contacts</a></li>
<li><a href="#"> Calendar</a></li>
</ul>
</li>
<li><a href="#"> Setup</a></li>
<li><a href="#"> Tools</a></li>
</ul>
</li>
公司,当访问控制器CompanyInformation
时,信息应返回活动状态。有没有办法使用某种通配符,说明在此控制器下访问任何操作时应用活动类?