【问题标题】:adding a css class with Html.TextBox用 Html.TextBox 添加一个 CSS 类
【发布时间】:2010-06-14 14:50:52
【问题描述】:

尝试添加“类”html 属性,但我认为关键字“类”会导致问题。

<%: Html.TextBox("name", "value", new {class: " required "})%>

有解决办法吗?

【问题讨论】:

    标签: asp.net html asp.net-mvc html-helper


    【解决方案1】:

    只需在“类”前加上“@”,因为它是reserved keyword

    <%: Html.TextBox("name", "value", new { @class: " required "})%>
    

    如果您需要有关 @ 关键字的一些背景知识,this 是一个很好的 SO 问题来阅读。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-03
      • 2013-07-19
      • 1970-01-01
      相关资源
      最近更新 更多