【发布时间】:2012-07-27 13:59:56
【问题描述】:
就像我在问题的标题中所说,是否可以将 cshtml 文件的 @helper 模板放在 App_Code 以外的文件夹中以使我的视图可见?
我发现了very nice article from ScottGu,但我的问题没有找到任何解决方案。
谢谢。
【问题讨论】:
标签: c# asp.net-mvc-3 templates html-helper
就像我在问题的标题中所说,是否可以将 cshtml 文件的 @helper 模板放在 App_Code 以外的文件夹中以使我的视图可见?
我发现了very nice article from ScottGu,但我的问题没有找到任何解决方案。
谢谢。
【问题讨论】:
标签: c# asp.net-mvc-3 templates html-helper
你可以,如果你把它们写成扩展方法(静态类的静态方法)。比如:
public static string AMethod(this HtmlHelper html, int arg)
...
让您在 cshtml 文件中调用方法
@Html.AMethod(5)
【讨论】: