【问题标题】:Asp.Net MVC @helper template in different folder than App_Code [duplicate]Asp.Net MVC @helper 模板位于与 App_Code 不同的文件夹中 [重复]
【发布时间】:2012-07-27 13:59:56
【问题描述】:

就像我在问题的标题中所说,是否可以将 cshtml 文件的 @helper 模板放在 App_Code 以外的文件夹中以使我的视图可见?

我发现了very nice article from ScottGu,但我的问题没有找到任何解决方案。

谢谢。

【问题讨论】:

    标签: c# asp.net-mvc-3 templates html-helper


    【解决方案1】:

    你可以,如果你把它们写成扩展方法(静态类的静态方法)。比如:

    public static string AMethod(this HtmlHelper html, int arg)
    ...
    

    让您在 cshtml 文件中调用方法

    @Html.AMethod(5)
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多