代码之家  ›  专栏  ›  技术社区  ›  Robin Maben

如何隐藏标准(现有)HTMLHER

  •  0
  • Robin Maben  · 技术社区  · 14 年前

    我已经创建了一组自定义HtmlHelper扩展。

    我想知道是否有可能阻止同一项目中的其他开发人员使用标准的HtmlHelpers。

    比如说,我有。。

    public static string CustomDropDown(this HtmlHelper html)
    {
       //Custom code here
    }
    

    我只想要 <% Html.CustomDropDown(..)%> 对开发人员可见而不是标准 <% Html.DropDownList(..)%> 或者它的任何重载。

    有没有人知道这是不是可能,怎么可能?

    5 回复  |  直到 12 年前
        1
  •  3
  •   Rune Baess    14 年前

    考虑改用EditorTemplates和/或DisplayTemplates。 这样,您的开发人员需要做的就是始终调用

    Html.EditorFor(model => model.MySpecialProperty);
    

    Html.DisplayFor(model => model.MySpecialProperty);
    
        2
  •  1
  •   John Farrell    14 年前

    为什么不直接告诉他们?

    “嘿,伙计们,这些定制助手好多了,你应该用它们。”。

    如果你有管理层的支持,这应该不是问题。

        3
  •  0
  •   Herman Cordes    14 年前

    我怀疑是否有任何故障保护的解决方案,也许这也不是一个很明智的做法。。。

    但你可以考虑把

    <add namespace="System.Web.Mvc" />
    

    在web.config中。

        4
  •  0
  •   Kai    14 年前

    NET MVC是一个开放的项目-您可以下载源代码并手动从HtmlHelper类中删除一些方法,重新生成此库并将其提供给您的开发人员。

        5
  •  0
  •   Patrick D'Souza ob1    12 年前

    你就不能重构你的代码吗??

    public class CustomControls
    {
        private readonly HtmlHelper _helper;
        public CustomControls(HtmlHelper helper)
        {
           _helper = helper;
    
        }
    
        public static string DropDown()
        {
           //Custom code here
        }
     }
    
     public CustomControls CustomControls(this HtmlHelper helper)
     {
        return new CustomControls(helper);
     }
    

    用法:

    <%:  Html.CustomControls().DropDown()  %>