Asp.Net Mvc highlighting current page link technique?

Viewed 17505

I need to highlight active link in the menu. My menu is in the master page by the way. I'm looking for the best way to implement this? Any ideas?

6 Answers

The simplest solution:

1) Connect jQuery to @RenderBody ()

2) On Layout

...                        
<li class="nav-item">
    <a class="nav-link text-dark" id="navItemPortfolio" asp-area="" asp-controller="Home" asp-action="Portfolio">Portfolio</a>
</li>

...

3) Write something similar on your page (View)

<script>
    $(function () {
        $("#navItemPortfolio").addClass("active");
    });
</script>

I'm pretty sure you can do this with pure CSS. It involves class selectors and faffing around with the body tag. I would go with the helper method every day of the week.

Related