-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
I have a parent model with a list of child models in an EditForm
/ObjectGraphDataAnnotationsValidator
/ValidateComplexType
context. I iterate over the child models and show form UI for each individual list item and want to show item-specific validation errors. For individual properties, I can show the ValidationMessage
, but I cannot find a way to show validation errors for the item itself.
Expected Behavior
I want a method to show child-model specific errors that are not bound to individual properties
Steps To Reproduce
I have extracted a repository containing code that shows the issue: https://github.com/Tragetaschen/blazor-nested-list-validation
There is a parent model containing a list of child models (with some validation rules)
https://github.com/Tragetaschen/blazor-nested-list-validation/blob/main/Pages/ParentModel.cs#L7-L10
The child model has a couple of properties and an IValidatableObject
implementation:
https://github.com/Tragetaschen/blazor-nested-list-validation/blob/main/Pages/ChildModel.cs#L13-L19
Note that this does not reference individual fields in the validation result.
In the EditForm
, I can reference the entire ValidationSummary
that shows all errors including those for the child model, I can reference the errors for individual properties of the child model, but I cannot get errors on the child model level.
https://github.com/Tragetaschen/blazor-nested-list-validation/blob/main/Pages/Form.razor#L15-L18
To reproduce, "Add" a child model, fill the Req field and then "Submit" leaving the Name and Alt fields empty. You will see the child model error in the validation summary, but not at the individual item level.
Exceptions (if any)
No response
.NET Version
6.0.400-preview.22301.10
Anything else?
No response