blazorblazor-server-sidemudblazor

How to render options for MudSelect?


I'm learning to use MudBlazor, and I'm starting with a simple MudSelect element like so:

<MudSelect Label="Select..." @bind-Value="_selectedFruitCode">
    @foreach(var fruitCode in fruitCodes)
    {
        Console.WriteLine(fruitCode.Descr);
        <MudSelectItem Value=@fruitCode.Code>@projectCode.Descr</MudSelectItem>
    }
</MudSelect>

I see the fruits logged on the console, and I see that the selection defaults to the value I assign to _selectedFruitCode in the constructor, but when I click to make a selection, no selections appear.

What am I doing wrong?


Solution

  • It turns out that somehow, the server side rendering wasn't turned on, so no interactive components could work.

    I had to add to the page
    @rendermode InteractiveServer

    To get that to build, I also had to add to _Imports.razor
    @using static Microsoft.AspNetCore.Components.Web.RenderMode

    And to MainLayour.razor, I had to add
    <script src="_framework/blazor.server.js"></script>