There are two ways to do custom model validation in ASP.NET Core:
- A custom attribute subclassed from
ValidationAttribute
. This is useful when you want to apply custom business logic to a particular model property with an attribute. - Implementing
IValidatableObject
for class-level validation. Use this instead when you need to do validation on an entire model at once.
The documentation has examples of both. In your case, IValidatableObject
would probably be the best approach.