从HTML辅助标识以下划线更换周期preventing ASP.NET MVC [英] Preventing ASP.NET MVC from Replacing period with underscore in Html Helper IDs

查看:100
本文介绍了从HTML辅助标识以下划线更换周期preventing ASP.NET MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚走升级到最新的ASP.NET MVC发布候选,我注意到,当使用HTML辅助,用了一段任何名称。在它都会有这个换成下划线_的时候,元素的ID被输出。

Having just upgraded to the latest ASP.NET MVC Release Candidate I noticed that, when using Html Helpers, any name with a period "." in it will have this replaced by an underscore "_" when the element's ID is output.

我相信这是<一个href=\"http://stackoverflow.com/questions/350292/how-do-i-get-jquery-to-select-elements-with-a-period-in-their-id\">to援助使用jQuery 和使用期限在使用ModelBinders的帮助。这已经打破了所有我们的JavaScript,它使用的原型,作为ID的都发生了变化。

I believe this is to aid in using JQuery and the use of the period is to aid in the use of ModelBinders. This has broken all of our javascript, which uses prototype, as the IDs have all changed.

有没有一种方法可以轻松地关闭此功能?

Is there a way to turn this feature off easily?

推荐答案

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

From the ASP.NET MVC RC1 Release notes (page 15).

在此版本中,默认情况下,点
  字符被自动替换
  在值了下划线
  ID属性。因此,例如文本框
  呈现以下标记:

In this release, by default the dot character is automatically replaced with an underscore in the value of the ID attribute. Thus the example TextBox renders the following markup:

&LT;输入
  类型=TEXTNAME =Person.FirstName
  ID =Person_FirstName/&GT;

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

To change the default replacement character, you can set the HtmlHelper.IDDotReplacementChar property to the character that you want to use instead.

仅供参考。查看源$ C ​​$ c。在 HTTP://www.$c$cplex.com/aspnet ,它看来,在RC1属性的真名是IdAttributeDotReplacement。有关code片断如下。为了保持点,你只是将此属性设置为点字符 - 即,与本身替换点字符

FYI. Looking at the source code at http://www.codeplex.com/aspnet, it appears that the real name of the property in RC1 is IdAttributeDotReplacement. The relevant code snippet is below. To keep the dot, you'd just set this property to the dot character -- i.e., replace the dot character with itself.

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

这篇关于从HTML辅助标识以下划线更换周期preventing ASP.NET MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆