You can use this JavaScript\jQuery
code:
// Sets active link in Bootstrap menu
// Add this code in a central place used\shared by all pages
// like your _Layout.cshtml in ASP.NET MVC for example
$('a[href="' + this.location.pathname + '"]').parents('li,ul').addClass('active');
It’ll set the <a>
‘s parent <li>
and the <li>
‘s parent <ul>
as active.
A simple solution that works!
Original source:
Bootstrap add active class to li