Date validation with Dataannotation

Asked

Viewed 298 times

0

I wanted to know if you have how to validate if the Date entered is higher or not than the current date using Annotation, or if I have to deal with the same controller. If you can, please provide an example.

1 answer

4


You can do this by creating a class that derives from RangeAttribute:

public class DateAttribute : RangeAttribute
{
    public DateAttribute()
      : base(typeof(DateTime), DateTime.Now.ToShortDateString(), DateTime.MaxValue.ToShortDateString()) { }
}

Source

  • I liked that answer here too, but it’s on SOF in English. I don’t know what the policy is for the use of English community information here on.SOF: http://stackoverflow.com/questions/19882296/mvc4-data-annotation-compartwo-dates

  • @Stillbuggin I put the link to the question in my answer

Browser other questions tagged

You are not signed in. Login or sign up in order to post.