【问题标题】:TextBoxFor show date without timeTextBoxFor 显示没有时间的日期
【发布时间】:2015-04-05 23:14:58
【问题描述】:

我想以 MM/dd/yy 格式在文本字段中显示日期。我将模型类描述为:

public class VacancyFormViewModel
{
    public int? ID { get; set; }
    [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yy}")]
    public DateTime SurgeryDate { get; set; }

当然,我可以用EditorFor代替TextBoxFor

@Html.EditorFor(p => p.SurgeryDate, new { @class = "form-control" })

问题是 css 样式,客户想要应用 bootstrap 样式,但这些样式已损坏:

如果我设置 TextBoxFor 而不是 EditorFor 我会得到带时间的日期:

@Html.TextBoxFor(p => p.SurgeryDate, new { @class = "form-control" })

有什么办法可以解决我的问题吗?或为EditorFor 应用样式,或无时间显示TextBoxFor,还是第三种方式?

【问题讨论】:

    标签: css asp.net-mvc twitter-bootstrap razor html.textboxfor


    【解决方案1】:

    您可以像这样在TextBoxFor helper 中指定日期格式:

    @Html.TextBoxFor(m => m.SurgeryDate, "{0:MM/dd/yy}",  new { @class = "form-control" })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-03
      • 1970-01-01
      • 2014-10-15
      • 2014-12-21
      • 2016-01-16
      • 2013-04-03
      • 1970-01-01
      相关资源
      最近更新 更多