Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Html.ActionLink cannot be used in global Razor helper

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?

like image 431
Marthijn Avatar asked Oct 18 '11 13:10

Marthijn


1 Answers

You could add the following line to your helper, to define Html

  var Html = ((System.Web.Mvc.WebViewPage)WebPageContext.Current.Page).Html; 

(Copied from this answer)

like image 99
GvS Avatar answered Sep 28 '22 06:09

GvS