gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 10:46:17 25 4
gpt4 key购买 nike

我想使用自定义@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?

最佳答案

将此 using System.Web.Mvc.Html; 添加到文件顶部

关于asp.net-mvc-3 - System.Web.Mvc.HtmlHelper'不包含 'ActionLink'的定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12692011/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com