Declare the property in the parent class as virtual:
public class MyModelBase
{
public virtual string Name { get; set; }
}
public class MyModel : MyModelBase
{
[Required]
public override string Name { get; set; }
public string SomeOtherProperty { get; set; }
}
Or you could use a MetadataType to handle the validation (as long as you're talking about DataAnnotations...otherwise you're stuck with the example above):
class MyModelMetadata
{
[Required]
public string Name { get; set; }
public string SomeOtherProperty { get; set; }
}
[MetadataType(typeof(MyModelMetadata))]
public class MyModel : MyModelBase
{
public string SomeOtherProperty { get; set; }
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…