2

I am using the following in my model for a date control

   [DataType(DataType.DateTime)]
   public DateTime txtDateAppCompletion { get; set; }

I also tried DataType.Date as I only want a date input.

   [DataType(DataType.Date)]
   public DateTime txtDateAppCompletion { get; set; }

For some reason when I run the form and I type anything that is not a date it does not validate it, not on server or on client(client validation is enabled).

Any Idea why I am having this problems? How to solve it?

1 Answer 1

2

Ok, after some research I found this in a Microsoft book.

■ Caution Even though [DataType] looks like a validation attribute along with the others in Data Annotations, ASP.NET MVC does not treat it as one, so don’t expect [DataType(DataType.EmailAddress)] to validate for legal e-mail addresses! [DataType] is an anomaly; even though it inherits from System.ComponentModel.DataAnnotations.ValidationAttribute, its IsValid() method is hard-coded to return true regardless of the property’s value. Microsoft has explained that [DataType] is only meant to serve as a hint for formatting data in a scaffolded UI...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.