MVC3 date validation

admin

Administrator
Staff member
<a href="http://thewayofcode.wordpress.com/2...ry-validation-with-data-annotations-in-mvc-3/" rel="nofollow">http://thewayofcode.wordpress.com/2...ry-validation-with-data-annotations-in-mvc-3/</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

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

[DataType(DataType.Date)]
[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

Code:
  @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.