Reputation: 3402
I've created a global .cshtml Razor file in the App_Code folder of my MVC project to declare @helper functions. The problem is I can't use Html.ActionLink (or the other extensions) in the helper functions. I have tried to import the classes via a @using but that didn't work. Any ideas?
Upvotes: 6
Views: 1951
Reputation:
Further to the accepted answer, to make @Html available throughout the helper file:
@using System.Web.Mvc.Html
...
@functions {
protected static new System.Web.Mvc.HtmlHelper Html
{
get
{
return ((System.Web.Mvc.WebViewPage)WebPageContext.Current.Page).Html;
}
}
}
Upvotes: 2
Reputation: 52501
You could add the following line to your helper, to define Html
var Html = ((System.Web.Mvc.WebViewPage)WebPageContext.Current.Page).Html;
Upvotes: 7