I have a couple model classes like so:
public class MyModelBase
{
public string Name { get; set; }
}
public class MyModel : MyModelBase
{
public string SomeOtherProperty { get; set; }
}
How can MyModel add a [Required] attribute to the Name property?
Try using a metadata class. It’s a separate class that is referenced using attributes that lets you add data annotations to model classes indirectly.
e.g.
ASP.NET MVC (including Core) offers similar support for its attributes like
FromQuery, via theModelMetadataTypeAttribute.