Using Bootstrap 4 and need to add the active class to navigation items to reflect current Razor page (new razor pages in Core 2.0). How can I find out which page/controller I am on so I can add the active class name to the proper:
<li><a class="active">...
Thanks.
Update: I was able to solve this with the following code in my page initializer:
@{
var _action = this.Url.ActionContext.ActionDescriptor.DisplayName;
var NavDashboard = "/abc";
...
}
Then I can add the "active" class in each nav items like:
<a asp-page="@NavDashboard" class="nav-link@(_action=="@NavDashboard" ? " active" : string.Empty)">Dashboard</a>
Rinse and repeat for each nav item.