I am trying to create a custom attribute in my MVC 5 web application to validate that a DateTime field falls within 30 to 50 days of the current date. If the date does not fall between the 30 to 50 day window, an error is thrown. I tried using this post to build my attribute, but I'm not sure where I'm going wrong with my code. Currently, this code builds but nothing happens when I enter an invalid date.
public class CustomDateAttribute : RangeAttribute
{
public CustomDateAttribute()
: base(typeof(DateTime),
DateTime.Now.AddDays(30).ToShortDateString(),
DateTime.Now.AddDays(50).ToShortDateString()
)
{ }
}