System.Web.Mvc.HtmlHelper'不包含定义'ActionLink的“ [英] System.Web.Mvc.HtmlHelper' does not contain a definition for 'ActionLink'
问题描述
我想使用自定义@ Html.ActionLink
我尝试使用下面的code: -
公共静态类LinkExtensions
{
公共静态MvcHtmlString MyActionLink(
这个的HtmlHelper的HtmlHelper,
串LINKTEXT,
串动,
串控制器)
{
VAR currentAction = htmlHelper.ViewContext.RouteData.GetRequiredString(行动);
VAR currentController = mlHelper.ViewContext.RouteData.GetRequiredString(控制器); 如果(动作== currentAction&放大器;&安培;控制器== currentController)
{
变种锚=新TagBuilder(一);
anchor.Attributes [HREF] =#;
anchor.AddCssClass(currentPageCSS);
anchor.SetInnerText(LINKTEXT);
返回MvcHtmlString.Create(anchor.ToString());
} 返回htmlHelper.ActionLink(LINKTEXT,动作,控制器);
}
}
从<一个href=\"http://stackoverflow.com/questions/5084635/custom-actionlink-helper-that-knows-what-page-youre-on\">Custom ActionLink的帮手知道你在什么页
但我正在逐渐
System.Web.Mvc.HtmlHelper'不包含一个定义
ActionLink的',没有扩展方法'ActionLink的接受第一
类型'System.Web.Mvc.HtmlHelper的说法可以找到(你
缺少using指令或程序集引用?
块引用>解决方案将此
使用System.Web.Mvc.Html;你的文件顶部
I would like to use custom @Html.ActionLink
I am trying to use the following code:-
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); } }
From Custom ActionLink helper that knows what page you're on
But I am getting
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?
解决方案Add this
using System.Web.Mvc.Html;
on top of your file这篇关于System.Web.Mvc.HtmlHelper'不包含定义'ActionLink的“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!