加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc-3 – System.Web.Mvc.HtmlHelper’不包含’ActionLi

发布时间:2020-12-15 18:39:19 所属栏目:asp.Net 来源:网络整理
导读:我想使用custom @ Html.ActionLink 我试图使用以下代码: public static class LinkExtensions{ public static MvcHtmlString MyActionLink( this HtmlHelper htmlHelper,string linkText,string action,string controller) { var currentAction = htmlHelpe
我想使用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添加在您的文件的顶部

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读