12345678910111213141516171819202122232425 |
- using Microsoft.AspNetCore.Mvc.Rendering;
- namespace WebApplicationSample.Helpers
- {
- public static class HtmlHelpers
- {
- public static string IsActive(this IHtmlHelper html, string controller = null, string action = null, string activeClass = "active")
- {
- var actualAction = (string)html.ViewContext.RouteData.Values["action"];
- var actualController = (string)html.ViewContext.RouteData.Values["controller"];
- if (string.IsNullOrEmpty(controller))
- {
- controller = actualController;
- }
- if (string.IsNullOrEmpty(action))
- {
- action = actualAction;
- }
- return controller == actualController && action == actualAction ? activeClass : string.Empty;
- }
- }
- }
|