【问题标题】:Date from Model does not display in TextBoxFor模型中的日期不显示在 TextBoxFor 中
【发布时间】:2021-04-30 18:14:31
【问题描述】:

我正在使用Html.TextBoxFor 来设置和显示来自模型的日期。它们在设置值时工作正常,但是当我从数据库中检索值时,它们不显示日期:

这是我的 HTML:

@Html.TextBoxFor(x=>x.effectiveDate, "Select Effective Date", new {@class="date form-control", id= "reqEffectiveDate" })

如果我切换到@Html.EditorFor,则会显示日期,但该元素不再像页面上的其他“表单控制”元素那样显示,并且单击该框不再显示日期选择器:

【问题讨论】:

    标签: asp.net asp.net-mvc


    【解决方案1】:

    EditorFor 默认不应用任何 CSS 类,除非您定义了自定义编辑器模板。

    您需要将一组 HTML 属性传递给编辑器:

    @Html.EditorFor(x => x.effectiveDate, new { htmlAttributes = new { @class = "date form-control", id = "reqEffectiveDate" } })
    

    【讨论】:

      猜你喜欢
      • 2013-04-03
      • 2015-09-14
      • 2015-04-05
      • 2021-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多