【问题标题】:Is it possible to make an Html.EditorFor greyed out?是否可以使 Html.EditorFor 变灰?
【发布时间】:2015-09-23 18:38:59
【问题描述】:

到目前为止,我有这个,它是只读的,但我希望它是灰色的。我需要它成为编辑器,因为我使用的是引导程序,它看起来比文本框更好。

@Html.EditorFor(model => model.EndDate, new { htmlAttributes = new { @class = "form-control", @readonly = "readonly" } })

【问题讨论】:

  • 我需要它成为 EditorFor?不,你不。 TextBoxFor() 将生成 。它的 html 属性(@class = "form-control")决定了它的外观,可以使用TextBoxFor() 轻松添加
  • 你说得对,我使用 TextBoxFor() 并为其添加背景颜色。

标签: html model-view-controller views


【解决方案1】:

可以使用TextBoxFor,只需稍微改写一下即可:

    @Html.TextBoxFor(model => model.EndDate, new { @class = "form-control", @readonly = "readonly" })

这样它会添加您的 form-control 类。

【讨论】:

    猜你喜欢
    • 2015-07-23
    • 1970-01-01
    • 1970-01-01
    • 2011-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-27
    相关资源
    最近更新 更多