How do I set the default value in select control?

The value property in the HTML <select> control can be utilized to set the default value. 

@page "/dropdown" 

<select class="form-control" value="@defaultValue.." @onchange="@OnSelect" style="width:150px"> 

@foreach (var template in templates)
{ 
<option value=@template>@template</option> 
} 

</select> 

<h5>@selectedString</h5> 

@code  
{ 
List<string> templates = new List<string>() { "America", "China", "India", "Russia", "England" }; 
string defaultValue = "India"; 
string selectedString = ""; 
void OnSelect(ChangeEventArgs e) 
{ 
         selectedString = "Selected Country is: " + e.Value.ToString(); 
} 
} 

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.