Reputation: 53
I have common issue to that How to change default validation error message in ASP.NET MVC?
I'm trying to set default validation message for all types in app but I use MVC3 and Razor engine. Unfortunately ssg solution doesn't work for me.
Upvotes: 3
Views: 3521
Reputation: 19
I know this is an old post but..
I just create C# validation code to determine if it isn't valid then return a validation message for an invalid string length.
if (String.IsNullOrEmpty(ValidEIN))
{
Validation.Add("EIN",
Validator.StringLength(0, 0, "Employee ID doesn't exist.")
);
}
Upvotes: 1
Reputation: 3034
This appears to be a problem in MVC3. http://forums.asp.net/t/1512140.aspx/1/10
Here are 2 possible workarounds.
1) Write a custom validation attribute with your own error message.
2) Do it client-side. Create a custom ClientDataTypeModelValidatorProvider, how to do this with MVC2 is explained here, I haven't tried it for MVC3. There is also some good info here.
Upvotes: 0
Reputation: 32437
Take a look at Model Metadata and Validation Localization using Conventions
Upvotes: 1