如何更改所有消息 int
字段,而不是说:The field must be a number
在英语中,它显示:El campo tiene que ser numerico
在西类牙语中。
有办法吗?
最佳答案
如果您碰巧从 ASP.NET MVC 4 开始使用,请查看这篇文章:
Localizing Default Error Messages in ASP.NET MVC and WebForms
基本上,您必须在 Application_Start()
中添加以下代码段Global.asax
中的方法:
ClientDataTypeModelValidatorProvider.ResourceClassKey = "Messages";
DefaultModelBinder.ResourceClassKey = "Messages";
在 Visual Studio 中的解决方案资源管理器中右键单击您的 ASP.NET MVC 项目,然后选择
Add => Add ASP.NET Folder => App_GlobalResources
.现在添加
.resx
此文件夹中名为 Messages.resx
的文件.最后在该
.resx
中添加以下字符串资源文件:Name Value
==== =====
FieldMustBeDate The field {0} must be a date.
FieldMustBeNumeric The field {0} must be a number.
PropertyValueInvalid The value '{0}' is not valid for {1}.
PropertyValueRequired A value is required.
你应该很高兴去。
请注意,您感兴趣的值是
FieldMustBeNumeric
.要将其本地化为西类牙语,您必须添加另一个名为 Messages.es.resx
的资源文件。 .在这个具体.resx
文件将资源值替换为:Name Value
==== =====
FieldMustBeNumeric El campo {0} tiene que ser numerico.
如果您碰巧在向下使用 ASP.NET MVC 3,此解决方案可以帮助您实现相同的结果:https://stackoverflow.com/a/2551481/114029
关于asp.net-mvc - 该字段必须是数字。如何将此消息更改为另一种语言?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12099466/