ASP.net MVC Data Annotations DateTime Default Value

折月煮酒 提交于 2019-12-01 17:04:26

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

Try making the DOB DateTime nullable like @Mayo states:

public DateTime? DOB { get; set; }

DateTime is of type struct. So, by default DateTime cannot be null. It has default value equal to '01/01/0001'. Solution to your problem is to use the nullable DateTime? type. If you want it to default to some value like '01/01/2014', then you can assign value like: DOB = new DateTime(2014, 01, 01);

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!