I am getting a strange issue with DataAnnotations in ASP.NET MVC 2which I am unable to get the hand of.
I am trying to validate a DateTime
In a Model Class I have defined
private DateTime _dateFrom;
[Required(ErrorMessage="Date is required")]
public DateTime DateFrom
{
get { return _dateFrom; }
set { _dateFrom = value; }
}
On the client side validation this works fine. However the server side validation always fails returning the "Date is required" error message.
If I change the Public property as below everything validates fine.
[Required(ErrorMessage="Date is required")]
public string DateFrom
{
get { return _dateFrom.ToShortDateString(); }
set { _dateFrom = DateTime.Parse(value); }
}
But this doesn't seem like the right way to go.
Am I missing something here? (this isn't a date parsing issue)
thanks for helping out, Dennis