I'm developing an app in Blazor using .NET 8 and MudBlazor, and I have a user edit form where I want to preselect the user's role in a MudSelect component. Each user has an iIdRoles field that identifies their role, and MudSelect is bound to a list of roles (Data.LstRoles) where each role has an iIdRoles and a vchRoleName.
My problem is that when I select a user to edit, the MudSelect appears empty instead of showing the role name of the selected user.Here is the code I use in my .razor component:
<MudSelect T="Roles" Label="Rol" Variant="Variant.Outlined" @bind-Value="Data.UsuariosSelected.Rol" AnchorOrigin="Origin.BottomCenter"> @foreach (var rol in Data.LstRoles) {<MudSelectItem T="Roles" Value="@rol">@rol.vchNombreRol</MudSelectItem> }</MudSelect>And this is the code I use to select the user when I click "Edit":
private async Task OnClickUsuarioSelected(Usuarios usuarios){ Data.UsuariosSelected = usuarios; await OnUsuariosSelected.InvokeAsync(usuarios);}