I have a DateTime field in my model that is shown in a form in my view like this:
<div class="editor-field">
@Html.EditorFor(model => model.Age)
@Html.ValidationMessageFor(model => model.Age)
</div>
When a new model is created and inserted into my database, I assign it a value of 09/11/1990 15:36:22
. If I try to edit this model using my view and do not change the value of Age
for my model, the model is validated and any changes to other fields are accepted and saved. However, if I change the Age
field to 07/27/2010 15:36:22
I am getting a validation error" The value '07/27/2010 15:36:22' is not valid for Age.
But, the date 09/12/2010 15:36:22
is validated successfully. Any reason why this is happening? In the debugger, the value returned for invalid dates is 01/01/0001
.
Edit: I think this has to do with the culture for jquery-validate and my system, since the client side validation fails any date that is in DD/MM/YYYY format, while the server side validation is failing any date that is in MM/DD/YYYY format.