TextBoxFor显示日期,无需时间 [英] TextBoxFor show date without time

查看:61
本文介绍了TextBoxFor显示日期,无需时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to show date in text field in format MM/dd/yy. I described model class as:

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

当然,我可以使用 EditorFor 代替 TextBoxFor :

Of course, I can use EditorFor instead of TextBoxFor:

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

问题是css样式,客户希望应用引导样式,这些样式已损坏:

Problem is css styles, customer wants apply bootstrap styles, which are broken:

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

if I set TextBoxFor instead of EditorFor I get the date with time:

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

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

Any way to solve my problem? Or apply styles for EditorFor, or show TextBoxFor without time, or third way?

推荐答案

您可以在 TextBoxFor 帮助器中指定日期格式,如下所示:

You can specify date format in TextBoxFor helper like this:

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

这篇关于TextBoxFor显示日期,无需时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆