代码之家  ›  专栏  ›  技术社区  ›  Paul Shannon

防止ASP。NET MVC从Html助手ID中用下划线替换句点

  •  7
  • Paul Shannon  · 技术社区  · 17 年前

    我相信这是 to aid in using JQuery

    1 回复  |  直到 9 年前
        1
  •  14
  •   tvanfosson    17 年前

    来自ASP。NET MVC RC1发行说明(第15页)。

    在此版本中,默认情况下,点 字符会自动替换 ID属性。因此,示例TextBox 呈现以下标记:

    <input type="text" name="Person.FirstName" id="Person_FirstName" />

    要更改 默认替换字符,您可以 HtmlHelper。IDDotReplacementChar 我想改用。

    FYI。查看源代码 http://www.codeplex.com/aspnet ,RC1中属性的真实名称似乎是IdAttributeDotReplacement。相关代码片段如下。要保留点,您只需将此属性设置为点字符,即用其自身替换点字符。

    public static string IdAttributeDotReplacement {
        get {
            if (String.IsNullOrEmpty(_idAttributeDotReplacement)) {
                _idAttributeDotReplacement = "_";
            }
            return _idAttributeDotReplacement;
        }
        set {
            _idAttributeDotReplacement = value;
        }
    }
    
    推荐文章