dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.36k stars 9.99k forks source link

Blazor: Model-specific validation errors of a list of child models cannot be shown individually #42575

Open Tragetaschen opened 2 years ago

Tragetaschen commented 2 years ago

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 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

MariovanZeist commented 2 years ago

@Tragetaschen I had a similar requirement, https://github.com/dotnet/aspnetcore/issues/40306 I ended up with a system where each child was surrounded by an EditForm, and aggregated all errors in my main component. to show if there was an error in any of the subitems.

ghost commented 2 years ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

ghost commented 10 months ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.