HtmlHelpers in MVC 6
asp.net-core, asp.net-core-mvc, c#
Solution
In the method signature, `HtmlHelper` should be `IHtmlHelper`
See Example below
namespace Blah.Web.Helpers
{
public static class HtmlHelpers
{
public static string IsActive(this IHtmlHelper htmlHelper, string controller, string action)
{
var routeData = htmlHelper.ViewContext.RouteData;
var routeAction = routeData.Values["action"].ToString();
var routeController = routeData.Values["controller"].ToString();
return (controller == routeController && action == routeAction) ? "active" : "";
}
}
}
Problem
I'm trying to port this code over to mvc 6, any help is appreciated, the code compiles but the method is not available in my views on `@Html.IsActive`. ``` using Microsoft.AspNet.Mvc.Rendering; namespace Blah.Web.Helpers { public static class HtmlHelpers { public static string IsActive(this HtmlHelper htmlHelper, string controller, string action) { var routeData = htmlHelper.ViewContext.RouteData; var routeAction = routeData.Values["action"].ToString(); var routeController = routeData.Values["controller"].ToString(); var returnActive = (controller == routeController && action == routeAction); return returnActive ? "active" : ""; } } } ``` In the View I have the namespace referenced: ``` @using Blah.Web.Helpers; ```