Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
In ASP.NET Core 5.0, an overload of the ValidationVisitor.Validate was added. The new overload accepts the top-level model instance that contains properties:
bool Validate(ModelMetadata metadata, string key, object model, bool alwaysValidateAtTopLevel);
+ bool Validate(ModelMetadata metadata, string key, object model, bool alwaysValidateAtTopLevel, object container);
ObjectModelValidator invokes this new overload of ValidationVisitor
to perform validation. This new overload is pertinent if your validation library integrates with ASP.NET Core MVC's model validation system.
For discussion, see GitHub issue dotnet/aspnetcore#26020.
Version introduced
5.0
Old behavior
ObjectModelValidator
invokes the following overload during model validation:
ValidationVisitor.Validate(ModelMetadata metadata, string key, object model, bool alwaysValidateAtTopLevel)
New behavior
ObjectModelValidator
invokes the following overload during model validation:
ValidationVisitor.Validate(ModelMetadata metadata, string key, object model, bool alwaysValidateAtTopLevel, object container)
Reason for change
This change was introduced to support validators, such as CompareAttribute, that rely on inspection of other properties.
Recommended action
Validation frameworks that rely on ObjectModelValidator
to invoke the existing overload of ValidationVisitor
must override the new method when targeting .NET 5 or later:
public class MyCustomValidationVisitor : ValidationVisitor
{
+ public override bool Validate(ModelMetadata metadata, string key, object model, bool alwaysValidateAtTopLevel, object container)
+ {
+ ...
}