在自定义助手中引用 @Html.Actionlink
Referencing @Html.Actionlink in a custom helper
我有一个自定义助手需要调用 Html.ActionLink
@helper GetLink(int id, string name)
{
@Html.ActionLink(name, "Index", "MyController", new { id = id }, null);
}
它在另一个页面上运行完美,但在我的自定义助手(名为 customhelpers.cshtml 并位于 App_Code 文件夹中)中,我收到以下错误:
'System.Web.WebPages.Html.HtmlHelper' does not contain a definition for 'ActionLink' and the best extension method overload 'System.Web.Mvc.Html.LinkExtensions.ActionLink(System.Web.Mvc.HtmlHelper, string, string, string, object, object)' has some invalid arguments
这意味着它找不到 Html.ActionLink class 但是我尝试引用相关的命名空间 (@using System.Web.MVC.Html) 但无济于事。
Htmlhelpers 无法从 App_Code 访问,但你可以看到一个不错的 workaround here from Paul Stovell (also mentioned by ScottGu)
我有一个自定义助手需要调用 Html.ActionLink
@helper GetLink(int id, string name)
{
@Html.ActionLink(name, "Index", "MyController", new { id = id }, null);
}
它在另一个页面上运行完美,但在我的自定义助手(名为 customhelpers.cshtml 并位于 App_Code 文件夹中)中,我收到以下错误:
'System.Web.WebPages.Html.HtmlHelper' does not contain a definition for 'ActionLink' and the best extension method overload 'System.Web.Mvc.Html.LinkExtensions.ActionLink(System.Web.Mvc.HtmlHelper, string, string, string, object, object)' has some invalid arguments
这意味着它找不到 Html.ActionLink class 但是我尝试引用相关的命名空间 (@using System.Web.MVC.Html) 但无济于事。
Htmlhelpers 无法从 App_Code 访问,但你可以看到一个不错的 workaround here from Paul Stovell (also mentioned by ScottGu)