У меня есть класс вроде этого:
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;}
}
но я знаю, что не могу, это вызывает ошибку. Что я должен сделать для этого требования?