gpt4 book ai didi

css - TextBoxFor 显示没有时间的日期

转载 作者:行者123 更新时间:2023-12-04 00:08:08 25 4
gpt4 key购买 nike

我想以 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 样式,这些样式已损坏:

enter image description here

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

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

enter image description here

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

最佳答案

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

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

关于css - TextBoxFor 显示没有时间的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28355155/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com