ASP.NET Core Active Route Tag Helper

ASP.NET Core Active Route Tag Helper

This C# class will create an anchor tag helper for use in ASP.NET Core. When the current Controller and Action match the specified attributes in an anchor tag, the value “active” will be appended to the class attribute.

To use it, you will need to import a tag helper into your _ViewImports.cshtml file.

@addTagHelper *, CoreWebApplication

Then, wherever you have a navigation anchor html tag, you can add a ASP.NET anchor tag helper. Notice the attribute “asp-nav-item”. Setting this value will active the logic.

Continue reading “ASP.NET Core Active Route Tag Helper”