I created an Html extension method in the Helper class, but I cannot get it to work. I implemented it, as shown in various textbooks.
My static MenuItemHelper 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 is:
Method not found: 'System.String System.Web.Mvc.Html.LinkExtensions.ActionLink (System.Web.Mvc.HtmlHelper, System.String, System.String, System.String)
EDIT:
It looks like the problem is with the application name. the folder is called MYAPP-MVC.Web, but in classes it translates to MYAPP_MVC.Web
I just tried this on a new application and it works
source
share