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?
Asked
Active
Viewed 1,943 times
6
-
1see this question - http://stackoverflow.com/questions/4710853/using-mvc-htmlhelper-extensions-from-razor-declarative-views – Graham Clark Oct 18 '11 at 13:54
2 Answers
7
You could add the following line to your helper, to define Html
var Html = ((System.Web.Mvc.WebViewPage)WebPageContext.Current.Page).Html;
2
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;
}
}
}