【发布时间】:2012-09-23 09:47:44
【问题描述】:
我想使用自定义@Html.ActionLink
我正在尝试使用以下代码:-
public static class LinkExtensions
{
public static MvcHtmlString MyActionLink(
this HtmlHelper htmlHelper,
string linkText,
string action,
string controller)
{
var currentAction = htmlHelper.ViewContext.RouteData.GetRequiredString("action");
var currentController = mlHelper.ViewContext.RouteData.GetRequiredString("controller");
if (action == currentAction && controller == currentController)
{
var anchor = new TagBuilder("a");
anchor.Attributes["href"] = "#";
anchor.AddCssClass("currentPageCSS");
anchor.SetInnerText(linkText);
return MvcHtmlString.Create(anchor.ToString());
}
return htmlHelper.ActionLink(linkText, action, controller);
}
}
来自Custom ActionLink helper that knows what page you're on
但我得到了
System.Web.Mvc.HtmlHelper' 不包含对 'ActionLink' 和没有扩展方法 'ActionLink' 接受第一个 可以找到“System.Web.Mvc.HtmlHelper”类型的参数(你是 缺少 using 指令或程序集引用?
【问题讨论】:
-
如果您确定已在配置中添加命名空间,您可能需要关闭并重新打开文件 - 检查此答案stackoverflow.com/questions/4136703/…
标签: asp.net-mvc-3 asp.net-mvc-4 html.actionlink