ASP.net MVC数据注释的DateTime默认值 [英] ASP.net MVC Data Annotations DateTime Default Value

查看:439
本文介绍了ASP.net MVC数据注释的DateTime默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的视图模型我有以下属性:

In my view model i have the following attribute:

 [Required]
 [DataType(DataType.Date, ErrorMessage="Please enter a valid date in the format dd/mm/yyyy")]
 [Display(Name = "Date of Birth")]
 public DateTime DOB { get; set; }

在我看来,我有以下几点:

In my view i have the following:

<div class="editor-label">
    @Html.LabelFor(model => model.DOB)
</div>
<div class="editor-field">
    @Html.EditorFor(model => model.DOB)
    @Html.ValidationMessageFor(model => model.DOB)
</div>

提交表单DOB的默认值是1/01/0001如何停止这个值被填充的汽车之前,我只是想要一个空场,当人们访问这个形式?

Before submitting the form the default value for DOB is 1/01/0001 how do i stop this value being auto populated, i simply want an empty field when people visit this form?

推荐答案

我相信你将不得不使用可空的DateTime?类型。日期时间不能为null因此它总是有一个值。

I believe you will have to use the nullable DateTime? type. DateTime cannot be null thus it will always have a value.

这篇关于ASP.net MVC数据注释的DateTime默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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