【发布时间】:2010-12-19 08:19:39
【问题描述】:
我有一个使用 DataAnnotations 的模型。类似的东西
public class Appointment {
[Required(ErrorMessage="Please enter your name")]
public string Name { get; set; }
[Required(ErrorMessage="Please enter your appointment date?")]
[DataType(DataType.Date, ErrorMessage="Appointment date is not a date")]
public DateTime AppointmentDate { get; set; }
}
“必需”属性尊重 ErrorMessage 中的值;也就是说,如果我不输入值,我会收到“请输入”消息。但是,如果我在 DateTime 字段中输入一个字符串,我会收到一条标准的系统错误消息“值 'blah' 对于 AppointmentDate 无效”。
我通过 ASP.NET MVC 代码进行了调试,似乎在 FormatException 的情况下,它没有从 propertyMetadata 中选择正确的显示名称。要么,要么我错过了一些明显的东西:/
有人遇到过这个问题吗?是我,还是只是测试版(我使用的是 ASP.NET MVC 2 Beta)?
【问题讨论】:
标签: asp.net-mvc error-handling data-annotations