Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4845

How to preselect a value in MudBlazor's MudSelect based on an ID of a selected object in Blazor? [closed]

$
0
0

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);}

Viewing all articles
Browse latest Browse all 4845

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>