问题
I'm using .NET Core 2.0. I have a POST action on my controller. It binds the data from the body of the request (JSON) into a C# DTO. On the DTO I have validation attributes - for instance:
[Required]
[MaxLength(512)]
public string email { get; set; }
These validators execute in the order that they are defined on the property.
I would like to short-circuit the validation if a prior validator fails. For example - if the required validation fails, don't execute the max length validation.
Is there a way to override the default model validation behavior to continue to the next property if one of the validators fails?
来源:https://stackoverflow.com/questions/48937926/short-circuit-model-validation-c-sharp