I've created an Html extension method in Helper class, but I can not get it to work. I've implemented it as seen on different tutorials.
My MenuItemHelper static class:
public static string MenuItem(this HtmlHelper helper, string linkText, string actionName, string controllerName)
{
var currentControllerName = (string)helper.ViewContext.RouteData.Values["controller"];
var currentActionName = (string)helper.ViewContext.RouteData.Values["action"];
var sb = new StringBuilder();
if (currentControllerName.Equals(controllerName, StringComparison.CurrentCultureIgnoreCase) && currentActionName.Equals(actionName, StringComparison.CurrentCultureIgnoreCase))
sb.Append("<li class=\"selected\">");
else
sb.Append("<li>");
sb.Append(helper.ActionLink(linkText, actionName, controllerName));
sb.Append("</li>");
return sb.ToString();
}
import namespace
<%@ Import Namespace="MYAPP.Web.App.Helpers" %>
Implementation on my master.page
<%= Html.MenuItem("TEST LINK", "About", "Site") %>
The error message I get:
Method not found: 'System.String System.Web.Mvc.Html.LinkExtensions.ActionLink(System.Web.Mvc.HtmlHelper, System.String, System.String, System.String)
EDIT: Seem like the problem is the application name. the folder is called MYAPP-MVC.Web, but in the classes it translates to MYAPP_MVC.Web
I just tried it on a fresh application and it works