MVC Localization of Default Model Binder

后端 未结 3 481
北恋
北恋 2021-01-02 20:45

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.

3条回答
  •  执念已碎
    2021-01-02 21:35

    In MVC3 do the following to change default messages:

    1. add the App_GlobalResources folder to your ASP.NET site
    2. add a new resource file, call it f.ex. MyResources.resx
    3. add these keys
      • PropertyValueRequired: A value is required.
      • PropertyValueInvalid: The value '{0}' is not valid for {1}.
    4. in Application_Start of global.asax.cs add the line DefaultModelBinder.ResourceClassKey = "MyResources";

提交回复
热议问题