I have an MVC application where I a model with Date property
[Required(ErrorMessage = "This is a required field.")]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}")]
[DataType(DataType.Date)]
public DateTime EventDate { get; set; }
I'm calling this in my view like this.
<div class="col-sm-9">
<span style="color:black">@Html.EditorFor(model => model.EventDate)</span><br />
@Html.ValidationMessageFor(m => m.EventDate, "", new { @class = "text-danger" })
</div>
Is there any way to disable past date while choosing a date. I tried to create a custom validation.
public class MyDateAttribute : ValidationAttribute
{
public override bool IsValid(object value)
{
DateTime d = Convert.ToDateTime(value);
return d > DateTime.Now;
}
}
and use it, but this removes the choosing a date
is it possible to disable past date on this Datetime annotation ?
Anyhelp is greatly appreciated.
Thank you