Reputation: 19
attempting to get a select/option html element to work in my blazor app, but the binding of the string continues to be "empty"
What am I not understanding?
/* It even defaults to so "A B C" but still is not bound */
<select bind="@divValue">
<option value="ABC">A B C</option>
<option value="DEF">D E F</option>
<option value="GHI">G H I</option>
</select>
@code {
string divValue = string.Empty;
....
/* value = string.Empty still*/
string test = divValue
}
Upvotes: 2
Views: 1772
Reputation: 1163
Use InputSelect instead of Select and bind value with its @bind-value attribute.
You can find the example here.
Thanks
Upvotes: 0
Reputation: 181
Change the data binding syntax
@page "/"
<div class="row ">
<select @bind="divValue" class="col-sm-2 form-control">
<option value="ABC">A B C</option>
<option value="DEF">D E F</option>
<option value="GHI">G H I</option>
</select>
</div>
<div class="row">
<input @bind="divValue" class="col-sm-2 mt-3 form-control"/>
</div>
@code {
public string divValue;
}
Upvotes: 1
Reputation: 14553
<select @bind="divValue">
<option value="ABC">A B C</option>
<option value="DEF">D E F</option>
<option value="GHI">G H I</option>
</select>
@divValue
@code {
string divValue;
}
Upvotes: 1