Changing the default ModelState error messages in ASP.NET MVC 3

后端 未结 2 874
萌比男神i
萌比男神i 2020-12-19 04:06

I have my resource files in separate assembly MyApp.Resources.dll. I can use the resources without any problem but the issue appears when I want to change (localize) the def

2条回答
  •  心在旅途
    2020-12-19 04:56

    There should be static properties on the DefaultModelBinder that you can set that will change the localization of the error messages...

    http://forums.asp.net/p/1512140/3608427.aspx

    Create a global resource class in App_GlobalResources, and set DefaultModelBinder.ResourceClassKey to the name of this class (for example, if you made "Messages.resx", then set ResourceClassKey to "Messages").

    There are two strings you can override in MVC 2:

    The string value for "PropertyValueInvalid" is used when the data the user entered isn't compatible with the data type (for example, typing in "abc" for an integer field). The default message for this is: "The value '{0}' is not valid for {1}." The string value for "PropertyValueRequired" is used when the user did not enter any data for a field which is not nullable (for example, an integer field). The default message for this is: "A value is required."

提交回复
热议问题