Where can I find tutorials on how exactly get this to work?
I am trying to have @helper in App_code directory of my MVC3 app, so far when I try to use them in other razor pages, they cannot be found.
Where can I find tutorials on how exactly get this to work?
I am trying to have @helper in App_code directory of my MVC3 app, so far when I try to use them in other razor pages, they cannot be found.
You need to call the helpers as static methods of the page name.
For example, if you have a helper named HelpMe
in App_Code/MyHelpers.cshtml
, you would write
@MyHelpers.HelpMe(...)
Scott Gu just wrote a blog post about this:
http://weblogs.asp.net/scottgu/archive/2011/05/12/asp-net-mvc-3-and-the-helper-syntax-within-razor.aspx
Look at this SO question and associated answer: Razor: Declarative HTML helpers
It does work, though I find that in the end, I usually opt for writing another extension method off of HtmlHelper.