MVC3 date validation


Staff member
<a href="" rel="nofollow"></a>

I tried to make the sample from the above link work, but cant get it correct. I am not sure what is it i am doing wrong?

I copied the Model validation

    [DisplayName("Start Date of Construction")]
    [DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}", ApplyFormatInEditMode = true)]
    public DateTime? StartDate { get; set; }

[DisplayNameAttribute("End Date of Construction")]
[DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}", ApplyFormatInEditMode = true)]
[DateGreaterThan("StartDate", "Estimated end date of construction must be greater than the start date of the construction")]
public DateTime? EndDateOf { get; set; }

Followed by DateGreaterThan code.

in View

  @Html.EditorFor(model =&gt; model.StartDate)
  @Html.EditorFor(model =&gt; model.EndDate)
   @Html.ValidationMessageFor(model =&gt; model.StartDate)
   @Html.ValidationMessageFor(model =&gt; model.EndDate)

But nothing fires in the button click, if anyone can shed some light.It would be really helpful or even any other different way of doing it is appreciated.Similarly trying to get a validation work from Model when selecting a value in the drop down and value entered in text box.