【问题标题】:Using Html.TextBoxFor with class and custom property (MVC)将 Html.TextBoxFor 与类和自定义属性一起使用 (MVC)
【发布时间】:2011-07-23 02:13:22
【问题描述】:

如何使用 TextBoxFor (MVC) 翻译该行:

<input id="Name" name="Name" type="text" data-bind="value: Name" class="title width-7" />

谢谢

【问题讨论】:

    标签: asp.net-mvc-3


    【解决方案1】:

    MVC 3 会将 html 属性名称中的下划线翻译成连字符,所以这样的东西应该可以解决问题

    @Html.TextBoxFor(m => m.Name, new { data_bind="value: Name", @class = "title width-7" })
    

    【讨论】:

    【解决方案2】:

    例如,

    如果要添加数据掩码

    @Html.TextBoxFor(m => m.BirthDate, new { @class = "form-control", data_mask = "date" })
    

    它将在html中生成

    data-mask="date"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-23
      相关资源
      最近更新 更多