【发布时间】:2012-01-25 02:21:51
【问题描述】:
如何显示自定义错误消息
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:d}")]
我的模型中的代码如下,
[Display(Name = "When was that document issued?")]
[DataType(DataType.Date, ErrorMessageResourceName = "DocumentIssueDate_DataType",ErrorMessageResourceType = typeof(CustomErrorMessages))]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:d}")]
public DateTime? DocumentIssueDate { get; set; }
在我的视图中,当我在日期文本框中输入 201 时,我收到以下错误消息。如何修改下面的错误信息。
值“201”对于 DocumentIssueDate 无效。
【问题讨论】:
-
你对
DocumentIssueDate_DataType有什么要求? -
资源文件 (.resx) 中的字符串消息。例如“日期必须输入为 dd/mm/yyyy(例如 31/01/1997)。”
标签: asp.net-mvc-3 data-annotations