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')]
So, to clear the validation errors, you can do something like this to a form : var fieldContexts = form. __MVC_FormValidation. fields; for(i = 0; i < fieldContexts.
In order for the Validator 's error message to display in the ValidationSummary , you need to set the Validator s Display="none" .
You can use the standard ASP.NET MVC ValidationSummary method to render a placeholder for the list of validation error messages. The ValidationSummary() method returns an unordered list (ul element) of validation messages that are in the ModelStateDictionary object.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With