So this doesn't work:
@helper DoesntWork(string text)
{
@Html.ActionLink(text, "Index", "Bar")
}
The way around it takes advantage of the fact that ActionLink is merely a static method inside an extension class. You need to reference the actual method, and pass the html context as the first argument.
@helper Works(string text)
{
@System.Web.Mvc.Html.LinkExtensions.ActionLink(
((System.Web.Mvc.WebViewPage)CurrentPage).Html, text, "Index", "Bar")
}
You should know that an extension method is just syntatic sugar that allows you to use Html.ActionLink("foo") instead of ActionLink(Html, "foo"). So if you can't use an it as an extension method, you can always fall back to just using it as a static method, if you can pass in the right first argument.
No comments :
Post a Comment
Note: Only a member of this blog may post a comment.