I read somewhere that view model properties must be only of strings.
e.g.
class PersonViewModel
{
public string Number {get;set;}
public string FullName {get;set;}
public string Birthday {get;set;}
}
How can I do validation of this model as easily as using ValidationAttributes
and ModelState.IsValid method in ‘normal’ model?
UPD:
I use AutoMapper to map ViewModel to this Domain Model:
class Person
{
public int ID {get;set;}
public string FullName {get;set;}
public DateTime Birthday {get;set;}
}
No, thats not true. With model binding, MVC will take care of it.
Here is a tutorial.
http://www.asp.net/mvc/tutorials/validation-with-the-data-annotation-validators-cs