开发者

Having razor @helper in App_code folder using ASP.NET MVC 3

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜