I have created a datepicker using MVC5 DataType.Date:
[DataType(DataType.Date)]
public DateTime ArrivalDate { get; set; }
How can I set the minimum available date to Today and disable all past dates?
Alternatively, is there an option to disable a custom range of dates?
I have tried to create a custom DateRangeValidator using the this answer, but with that I get the following error: named parameter type constraints
Here's my Date range validator:
public DateTime FirstDate = DateTime.Today.Date;
//public DateTime SecondDate { get; set; }
protected override ValidationResult IsValid(DateTime date, ValidationContext validationContext)
{
// your validation logic
if (date >= DbFunctions.TruncateTime(FirstDate))
{
return ValidationResult.Success;
}
else
{
return new ValidationResult("Date is not valid.");
}
}