0
[Required]
public string? Description { get; set; }

I am using <DataAnnotationsValidator />

I have the above property in a class and validating the model. Sometimes depending on some condition the Description field may not be a required field, how to remove the validation in that case?

Is it a way to programmatically remove the required attribute depending on the conditions?

Venkat
  • 1,702
  • 2
  • 27
  • 47
  • Does this answer your question? [Disable Required validation attribute under certain circumstances](https://stackoverflow.com/questions/5367287/disable-required-validation-attribute-under-certain-circumstances) – Progman Nov 13 '22 at 15:06
  • That one answers the MVC. This one is regarding the blazor – Venkat Nov 14 '22 at 07:15
  • I'm afraid you can't. You could try use [FluentValidation](https://docs.fluentvalidation.net/en/latest/blazor.html) for Blazor and then create a validator for your model using [conditional validation rules](https://docs.fluentvalidation.net/en/latest/conditions.html). – Prolog Nov 15 '22 at 16:52

0 Answers0