Click here to Skip to main content
16,004,192 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
i am using mvc5 in my model birthdate field but and set data annotation are as follwos:

[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:dd-MM-yyyy}"ApplyFormatInEditMode = true)
public System.DateTime stdreg_birthdate { get; set; }

but when i am enter in view date in birthdate in my textbox show the message "The field Date Of Birth: must be a date."

how to resolved....
thanks in advance

What I have tried:

i am tried to add web config file

and set data annotation in model properties but not yet.....
Posted
Updated 3-Oct-16 1:53am

1 solution

The DisplayFormat attribute is only for when you are showing the property in your view, it doesn't dictate how the data is bound to your model. You'll need to implement a custom binder for this.

I googled "mvc model binding date format" and found this, but there are many others

Custom Date Formats and the MVC Model Binder | greatrexpectations[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900