想要覆盖datetime“错误的格式消息”。
即默认情况下DateTime属性显示消息:: The value '12--2002' is not valid for * dateTime PropertyName: (DD/MM/YYYY).
但我希望通过一些资源文件显示此消息。
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; }
}
建议我最简单的方式。
答案 0 :(得分:0)
在App_Global_Resources中创建一个资源文件(例如“Messages.resx”。添加两个字符串:
PropertyValueInvalid({1}的值{0}无效。)
PropertyValueRequired。 (字段{0}是必需的。)
在Global.asax中添加:
DefaultModelBinder.ResourceClassKey = "Messages";