0

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; }

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 is a valid date format so why would it complain? Is there any way to fix this?

Thanks

1 Answer 1

0

try adding:

[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd-MM-yyyy}")]
Sign up to request clarification or add additional context in comments.

1 Comment

Unfortunately that doesn't work. I still get the validation message saying "The value '16-05-2013' is not valid for DateOfBirth. "

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.