说我有一个课程如下
class Person {
[Required]
public string Firstname;
[Required]
public string Lastname;
}
class Record {
[RequiredIfTrue("HasPerson")]
public Person Person;
[Required]
public bool? HasPerson;
}
然后我有一些观看代码
<div showIfTrue("HasPerson")>
@Html.EditorFor(m => m.Person.Firstname);
@Html.ValidationMessageFor(m => m.Person.Firstname);
...
</div>
我的字段不应该无法验证HasPerson
是否为假,但确实如此。有没有办法编写模型,以便正确验证?
即。有没有办法让类的属性继承父类的验证?