Say I have this property in my model:
[DisplayName("test")]
[Required(ErrorMessage = "required")]
public DateTime? SomeDate { get; set; }
when you type in "asdf" in Html.TextBoxFor(model => model.SomeDate)
, you get the validation error message "The value 'asdf' is not valid for test.".
How do you modify that message? ASP.NET MVC ignored [DataType(DataType.DateTime, ErrorMessage = 'some other message')]
Apparently my question was already answered at How to replace the default ModelState error message in Asp.net MVC 2? .
I'll summarize it here:
MyNewResource.resx
.PropertyValueInvalid
with the desired message format (e.g. "content {0} is invalid for field {1}"). If you want to change PropertyValueRequired
too add it as well.DefaultModelBinder.ResourceClassKey = "MyNewResource"
to your Global.asax startup code.You're all set.