防止ASP.NET MVC在Html Helper ID中使用下划线替换句点

刚刚升级到最新的ASP.NET MVC候选版本时,我注意到,当使用Html Helpers时,任何带有句点“。”的名称。 当输出元素的ID时,它将被下划线“_”替换。

我相信这是为了帮助使用JQuery ,并且使用句点是为了帮助使用ModelBinders。 这打破了我们使用原型的所有javascript,因为ID已全部更改。

有没有办法轻松关闭此function?

从ASP.NET MVC RC1发行说明(第15页)。

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

若要更改默认替换字符,可以将HtmlHelper.IDDotReplacementChar属性设置为要使用的字符。

仅供参考。 查看http://www.codeplex.com/aspnet上的源代码,看来RC1中属性的真实名称是IdAttributeDotReplacement。 相关的代码段如下。 要保留点,您只需将此属性设置为点字符 – 即,将点字符替换为自身。

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