覆盖(通过资源文件和显示消息)在asp.net的MVC属性数据类型不匹配消息 [英] Override dataType mismatch message of property in asp.net mvc(and display message through resource file)
问题描述
要覆盖的日期时间格式错误信息。
默认情况下,日期时间属性中显示的消息,即:: 值'12 --2002'是无效的*日期时间属性名:(DD / MM / YYYY)
但我想这个消息通过一些资源文件中显示。
want to override datetime "wrong format message".
i.e by default DateTime property display message:: The value '12--2002' is not valid for * dateTime PropertyName: (DD/MM/YYYY).
But i want this message to display through some Resource file.
public class candidateAddressViewModel
{ [Required(ErrorMessageResourceType = typeof(myApp.Resources.res.Resource),
ErrorMessageResourceName = "error_format")]
[Display(Name = "lived_from", ResourceType = typeof(myApp.Resources.res.Resource)), DisplayFormat(DataFormatString = "{0:dd-MM-yy}", ApplyFormatInEditMode = true)]
public DateTime? dateTimePropertyName{ get; set; }
}
我建议最简单的方式。
Suggest me easiest possible way.
推荐答案
创建App_Global_Resources(例如,Messages.resx资源文件添加两个字符串:
Create a resource file in App_Global_Resources (for example "Messages.resx". Add two strings:
PropertyValueInvalid(值{0} {1}无效。)
PropertyValueInvalid (Value {0} for {1} is invalid.)
PropertyValueRequired。 (现场{0}是必需的。)
PropertyValueRequired. (Field {0} is required.)
在您的Global.asax添加:
In your Global.asax add:
DefaultModelBinder.ResourceClassKey = "Messages";
这篇关于覆盖(通过资源文件和显示消息)在asp.net的MVC属性数据类型不匹配消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!