Cannot use Html.ActionLink in asp.net mvc spark files
Asked Answered
D

3

5

I'm using the spark view engine with my asp.net mvc application. In my aspx pages, I can succesfully use Html.Actionlink, but when I attempt it in spark files, it doesnt show up in intellisense, and when i try to run it anyway, i get:

Dynamic view compilation failed. c:\Users\midas\Documents\Visual Studio 2008\Projects\ChurchMVC\ChurchMVC\Views\Home\Index.spark(73,25): error CS1061: '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?)

I do have system.web.mvc referenced, and I have added in _global.spark. None of that helps. Any ideas?

Dumuzi answered 4/7, 2009 at 6:23 Comment(0)
M
9

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

This is where the helpers live.

<use namespace="System.Web.Mvc.Html" />
Maggiore answered 7/7, 2009 at 1:17 Comment(0)
G
4

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.

Gradate answered 4/4, 2010 at 11:14 Comment(0)
D
1

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(...)}

Driveway answered 15/1, 2010 at 20:16 Comment(1)
Oops! Sorry, mixed two articles - not "the same problem", a different one.Driveway

© 2022 - 2024 — McMap. All rights reserved.