Blazor Dropdown Select Code Example


Example: blazorstrap dropdown onchange


//Your answer should be in the cshtml:

<select class="form-control" @onchange="@OnSelect" style="width:150px">
@foreach (var template in templates)
{
<option value=@template>@template</option>
}
</select>

<h5>Selected Country is: @selectedString</h5>

//Then your @functions or @code if Blazor should look like:

@code {
List<string> templates = new List<string>() { "America", "China", "India", "Russia", "England" };
string selectedString = "America";

void OnSelect (ChangeEventArgs e)
{
selectedString = e.Value.ToString();
Console.WriteLine("The selected country is : " + selectedString);
}
}

Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable