Blazor: Model-specific validation errors of a list of child models cannot be shown individually #42575
Open
1 task done
Labels
area-blazor
Includes: Blazor, Razor Components
enhancement
This issue represents an ask for new feature or an enhancement to an existing one
feature-blazor-builtin-components
Features related to the built in components we ship or could ship in the future
Milestone
Is there an existing issue for this?
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 theValidationMessage
, 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 entireValidationSummary
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
The text was updated successfully, but these errors were encountered: