开发者

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

开发者 https://www.devze.com 2023-02-13 22:55 出处:网络
I don\'t quite understand how MVC 2 is validating the datatypes, or how I could inject my own error-string/language.

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

精彩评论

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