Asp.net MVC3 DefaultModelBinder Error Messages

There are many questions (and answers) on stackoverflow and another site about translating default error messages provided by DefaultModelBinder, such as this or this .

All the answers to these questions will mainly be asked to create a ressource (resx) file in App_GlobalResources and put a message for "PropertyValueInvalid".

This is good, but it works, but there is another message (for example, β€œxxx must be a number”), and the big question is: where the hell can I have a list of message keys used to check the model binding, with a description of the context, for which they are used, so can I translate each of them?

+4
source share
1 answer

When DefaultModelBinder.ResourceClassKey = "ResourceFileName";set in the Application_Start method, the DefaultModelBinder class uses other resource keys than defined in the resource file used by Asp.Net MVC.

When disassembling DefaultModelBinder, there is a GetUserResourceString method that reads from a custom resource file. These functions are only called twice with these message keys:

  • PropertyValueRequired (value required.)
  • PropertyValueInvalid (The value {{0} "is not valid for {1}.)

These are the only messages that can be set for DefaultModelBinder in MVC3.

+8
source

All Articles