Technically I prefer to perform this kind of conditional validation on Frontend side. Server side validation is meant usually only for security reasons, as a last resort or for a basic validation: Don't let users inject Potatoes instead of Integers.
So if you verify the maximum range boundaries that would be enough if the semantical validation is not critical from a security perspective.
If You insist or think that security can be broken and want to validate all the cases on Server side you can create a custom validation attribute by extending the .NET ValidationAttribute class:
https://learn.microsoft.com/de-de/dotnet/api/system.componentmodel.dataannotations.validationattribute?view=net-5.0
An example about how to use it here:
ASP.NET MVC: Custom Validation by DataAnnotation
If You're writing an API in Core .NET yep, as stated by Wootiae You could throw an Exception and let Core .NET return an HTTP code from the range 400 which indicates a "Bad format". This should be done in the API method BODY.
Something like this:
if (condition)
return HttpBadRequest("Bad Request. Out of Range.");
Anyway, frontend code should still enforce this.
Edited
As suggested by pinkfloydx33