MVC Localization of Default Model Binder
Posted
by Dai Bok
on Stack Overflow
See other posts from Stack Overflow
or by Dai Bok
Published on 2010-03-17T13:48:59Z
Indexed on
2010/03/17
13:51 UTC
Read the original article
Hit count: 360
Hi,
I am currently trying to figure out how to localize the error messages generated by MVC. Let me use the default model binder as an example, so I can explain the problem.
Assuming I have a form, where a user enters thier age. The user then enters "ten" in to the form, but instead of getting the expected error of
"Age must be beween 18 and 25."
the message
"The value 'ten' is not valid for Age."
is displayed.
The entity's age property is defined below:
[Range(18, 25, ErrorMessageResourceType = typeof (Errors),
ErrorMessageResourceName = "Age", ErrorMessage = "Range_ErrorMessage")]
public int Age { get; set; }
After some digging, I notice that this error text comes from the System.Web.Mvc.Resources.DefaultModelBinder_ValueInvalid in the MvcResources.resx file.
Now, how can create localized versions of this file?
As A solution, for example, should I download MVC source and add MvcResources.en_GB.resx, MvcResources.fr_FR.resx, MvcResources.es_ES.resx and MvcResources.de_DE.resx, and then compile my own version of MVC.dll?
But I don't like this idea. Any one else know a better way?
© Stack Overflow or respective owner