Onchange event of Select Control in Blazor app (net8) is not firing

683 views Asked by At

I am newcomer to blazor and writing a blazor web app. I would like to run some logic after the user has made a selection in the select control. I have tried both onchange and onselect events . The event is not firing. I will appreciate if someone could help me here.

@page "/"

<select id="ABC" @onchange="GroupSelected">
    <option>A</option>
    <option>B</option>
    <option>C</option>
</select>
<hr />
<label>@SelectedGroup</label>

@code
{
    string SelectedGroup = "Z";
    public void GroupSelected()
    {
        SelectedGroup += "A";
        StateHasChanged();
        return ;
    }
}
1

There are 1 answers

1
Mirza Osama Ejaz On

after the @page directive, add.. @rendermode InteractiveServer

it tells the compiler to interactively communicate with the server (where the C# code resides)

Hope it helps..