ASP.NET MVC DataAnnotations不接受DD-MM-yyyy格式 [英] ASP.NET MVC DataAnnotations doesn't accept dd-MM-yyyy format

查看:408
本文介绍了ASP.NET MVC DataAnnotations不接受DD-MM-yyyy格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的ASP.NET MVC 4项目中,我有一个使用DataAnnotations验证日期属性一个DATEOFBIRTH场...

In my ASP.NET MVC 4 project I have a DateOfBirth field that uses the DataAnnotations Validation Date Attribute...

[Required(ErrorMessage = "This field is required"), Date]
public DateTime DateOfBirth { get; set; }

我已经设置我的DatePicker控件以DD-MM-YYYY格式(默认是YYYY-MM-DD)。
但是,当我提交表单据我所知,日期格式不正确。

I have set the format of my DatePicker control to dd-MM-yyyy (default was yyyy-MM-dd). But when I submit the form I am told that the date format is not valid.

DD-MM-yyyy是一个有效的日期格式,所以为什么会抱怨?有什么办法解决这一问题?

dd-MM-yyyy is a valid date format so why would it complain? Is there any way to fix this?

感谢

推荐答案

尝试加入:

[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd-MM-yyyy}")]

这篇关于ASP.NET MVC DataAnnotations不接受DD-MM-yyyy格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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