Im using mudform with fluent validation and I’m trying to validate my child model in a child component. It works well if I’m passing the parent “request” class and using that directly in the child component. But it fails if I’m passing a child model like “Customer”.
Here is some simplified code:
Parent component
<MudForm @ref="_form" Model="_request" Validation="_validator">
<Customer Model="_request.Customer"></Customer>
</MudForm>
Child component
<MudTextField @bind-Value="@Model.CompanyName" For="() => Model.CompanyName" Label="Company name" />
<MudTextField @bind-Value="@Model.Address" For="() => Model.Address" Label="Address" />
<MudTextField @bind-Value="@Model.City" For="() => Model.City" Label="City" />
@code {
[Parameter]
public Customer Model { get; set; } = new();
I’ve seen some solutions using EditContext, but that isn’t available to MudForm. In case that’s my only option then I guess I need to change to a EditForm
.
But it feels really simply and a common problem so I don’t think it should be that hard. Another solution I was thinking was to use another MudForm directly inside the child component.
Do you have any best practice to this?