There's a lot of question (and answer) here on stackoverflow and other site about translating the default error messages provided by the DefaultModelBinder, such as this one or this one.
All answers to these questions basically proprose to create a ressource (resx) file under App_GlobalResources and put a message for "PropertyValueInvalid".
That's fine, it does works, but there is other message also (ex. "The value xxx must be a number") and the big question is : where in hell can I have a list of the messages key used for model binding validation, with a description of the con开发者_如何学编程text they are used for so I can translate each of them ?
When DefaultModelBinder.ResourceClassKey = "ResourceFileName";
is set in Application_Start method the DefaultModelBinder class uses other resource keys than defined in the resource file used by Asp.Net MVC.
While disassembling DefaultModelBinder there is a method GetUserResourceString that reads from the custom resource file. This functions is only called twice with these messages keys:
- PropertyValueRequired (A value is required.)
- PropertyValueInvalid (The value '{0}' is not valid for {1}.)
These are the only messages that could be set for DefaultModelBinder in MVC3.
精彩评论