说我在我的模型中有这个属性:
[displayName("test")] [required(ErrorMessage = "required")] public DateTime? SomeDate { get; set; }
当您在Html.TextBoxFor(model => model.someDate)中键入“asdf”时,您会收到验证错误消息“值asdf’对测试无效。
如何修改该消息? ASP.NET MVC忽略[DataType(DataType.DateTime,ErrorMessage =’some other message’)]
解决方法
显然我的问题已经在
How to replace the default ModelState error message in Asp.net MVC 2?回答。
我将在这里总结一下:
>为您的项目创建App_GlobalResources文件夹(右键单击项目 – >添加 – >添加ASP.NET文件夹 – > App_GlobalResources)。
>在该文件夹中添加一个resx文件。说MyNewResource.resx。
>使用所需的消息格式添加资源键PropertyValueInvalid(例如“content {0}对于字段{1}无效”)。如果你想改变PropertyValuerequired太多也添加它。
>将代码DefaultModelBinder.ResourceClassKey =“MyNewResource”添加到Global.asax启动代码。
你已经准备好了。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。