Код: Выделить всё
public class Employee
{
[Required]
public string Name { get; set; }
[Required]
public Address Address { get; set; }
}
public class Address
{
[Required]
public string Line1 { get; set; }
public string Line2 { get; set; }
[Required]
public string Town { get; set; }
[Required]
public string PostalCode { get; set; }
}
Код: Выделить всё
var employee = new Employee
{
Name = "Neil Barnwell",
Address = new Address
{
Line1 = "My Road",
Town = "My Town",
PostalCode = "" //
Подробнее здесь: [url]https://stackoverflow.com/questions/7663501/dataannotations-recursively-validating-an-entire-object-graph[/url]
Мобильная версия