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

Blazor @onchange event doesnt fire

$
0
0

In the Blazor WebAssembly application, the @onchange event attached to the element fails to trigger when selecting the "Weather" option. The goal is to dynamically render components based on the selected option, but the event doesn't respond as expected.

@page "/"<PageTitle>Home</PageTitle><h1>Hello, world!</h1>Welcome to your new app.<h2>Dynamic Component</h2><select @onchange="ChangeValue"> /*Doesn't fire */<option value="Default">select</option><option value="Weather">Weather</option></select>@if(selectedType is not null){<div class="p-2 mt-2"><DynamicComponent Type="selectedType"/></div>}else{<h3>Waiting...</h3>}@code{    private Type? selectedType;    private Dictionary<String, Type> components = new Dictionary<string, Type>()    {            ["Weather"] = typeof(Weather)    };    public void ChangeValue(ChangeEventArgs e)    {        Console.WriteLine("entre");        if (e.Value is String DropdownValue)        {            selectedType =  components[DropdownValue];        }        else        {            selectedType = null;        }    }}

Viewing all articles
Browse latest Browse all 4839

Trending Articles



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