DataAnnotations in ASP.NET MVC 2 - Stop MVC from applying RequiredAttribute to Non-nullable DateTime

Posted by jwwishart on Stack Overflow See other posts from Stack Overflow or by jwwishart
Published on 2010-03-21T23:32:34Z Indexed on 2010/03/21 23:41 UTC
Read the original article Hit count: 345

Im trying to create a custom version of the RequiredAttribute to replace the built in one and I've got it working for properties that have strings values, but with properties that are DateTime or integer for example, the default RequiredAttribute seems to be applied automatically (IF the property is not nullable!)

My problem is that i want to be able to specify a DateTime property as required using my custom required validator which gets the error message from a resources file (I don't want to have to tell the RequiredAttribute the type of the resource file and the key every time i apply it. That is why I'm making a custom one.)

How can i prevent the framework from applying the required attribute to properties of type DateTime and int etc without changing them to nullable.

Thanks

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about dataannotations