开发者

Validating datatypes... How/Where and custom error-string?

I don't quite understand how MVC 2 is validating the datatypes, or how I could inject my own error-string/language.

Given a date-field in a View-Model:

 public DateTime Appointment { get; set; }

I would get the following error if I fill in an invalid date into the form: The value '01开发者_如何转开发.03.20111' is not valid for Appointment.

I certainly know about DataAnnotations (DisplayName, Required etc.), but I don't know how the datatype-validation happens and where/how I could hook in?

Thx for any tipps sl3dg3


That message comes from the ModelBinder. You can write your own custom model binders if you would like. Scott Hanselman has examples here and here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜