Cannot use Html.ActionLink in asp.net mvc spark files

≡放荡痞女 提交于 2019-12-04 07:59:33

(Copied from Rei Roldán's answer in Spark discussion group)

This is where the helpers live.

<use namespace="System.Web.Mvc.Html" />

It is possible to get this error even with correct Web.config by declaring ActionLink with wrong argument types.

Example:

<%= Html.ActionLink(1, "bar") %>

Error:

Compiler Error Message: CS1928: 'System.Web.Mvc.HtmlHelper<Approval.WebSite.ViewsModels.HomeIndexPage>' 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)' has some invalid arguments

While this works:

<%= Html.ActionLink("foo", "bar") %>

So check your markup as well.

I had the same problem with Html.ActionLink in master layout. The reason was automatic Html encoding. Fixed by setting <pages automaticEncoding="false"> in web.config or by using !{Html.ActionLink(...)} instead of ${Html.ActionLink(...)}

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!