У меня есть такой класс:
public class Document
{
public int DocumentType{get;set;}
[Required]
public string Name{get;set;}
[Required]
public string Name2{get;set;}
}
Теперь, если я добавлю аннотацию данных [Required]
к свойствам Name
и Name2
, тогда все в порядке, и если Name
или Name2
пусты, проверка выдаст ошибку.
Но я хочу, чтобы поле Name
было обязательным, только если DocumentType
равно 1, а Name2
требовалось, только если DocumentType
равно 2.
public class Document
{
public int DocumentType{get;set;}
[Required(Expression<Func<object, bool>>)]
public string Name{get;set;}
[Required(Expression<Func<object, bool>>)]
public string Name2{get;set;}
}
но я знаю, что не могу, это вызывает ошибку. Что мне делать по этому требованию?