我想在ASP.NET Core MVC中添加带有NAV-Link的活动类
我需要与.nav-link添加一个活跃的类
<ul class="sidebar-nav" id="sidebar-nav">
<li class="nav-item">
<a asp-area="DemoArea" class="nav-link" asp-controller="Dashboard" asp-action="Index">Dashboard</a>
</li>
</ul>
I need to add an active class with the .nav-link
<ul class="sidebar-nav" id="sidebar-nav">
<li class="nav-item">
<a asp-area="DemoArea" class="nav-link" asp-controller="Dashboard" asp-action="Index">Dashboard</a>
</li>
</ul>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用jQuery来做到这一点,而不是最好的答案,但也有效。您可以根据需要添加菜单级别...请参阅下面的代码:
您可以使用.east函数在列表中的每个父项目上循环。
You can use jquery to do this, Not the best answer but it works too. And you can add menu levels as you want... see the code below:
You can use .each function to loop on each parent item in your list.
这是一个动态添加类的简单演示,按ViewBag值:
后端:
Here is a simple demo for dynamic add class by ViewBag value:
Backend:
我已经使用了静态类菜单螺旋桨和静态方法makeActiveClass,以及当传递值和routedata值匹配时,我已经传递了控制器名称和操作方法名称,然后它将返回活动类,而其他为null。
我已经称 makeactiveclass 锚标签助手
I have used the static class MenuStateHelper and static method MakeActiveClass along with that I have passed controller name and action method name when both passed values and RouteData value match then it will return active class else it will be null.
And I have called MakeActiveClass method on Anchor Tag Helper