asp.net-mvc-3 – System.Web.Mvc.HtmlHelper’不包含’ActionLink’的定义

前端之家收集整理的这篇文章主要介绍了asp.net-mvc-3 – System.Web.Mvc.HtmlHelper’不包含’ActionLink’的定义前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想使用custom @ 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’ does not contain a definition for
‘ActionLink’ and no extension method ‘ActionLink’ accepting a first
argument of type ‘System.Web.Mvc.HtmlHelper’ could be found (are you
missing a using directive or an assembly reference?

解决方法

使用System.Web.Mvc.Html添加在您的文件的顶部
原文链接:https://www.f2er.com/aspnet/253578.html

猜你在找的asp.Net相关文章