RequiredIf conditional attribute in .net Core

Viewed 3859

How to achieve RequiredIf conditional operation in .NET Core for Model based validation.

In ASP.NET MVC, had used with ExpressiveAnnotation package but its not working for .NET Core.

2 Answers

You can extend RequiredAttribute to check the property value and according to that manually check IsNullOrWhiteSpace of current property .

You can find the code sample here . Here is another code sample using custom ValidationAttribute .

Related