I would like to bind a value to a property that i would like to post later through my dropdownlist. My problem is that i cant use @Bind-Value="@name" inside a select with options. I Get this error message RZ9991 The attribute names could not be inferred from bind attribute 'bind-value'. Bind attributes should be of the form 'Bind' or 'Bind-Value' along with their corresponding optional parameters like 'bind-value:event', 'bind:format' etc
I have tried to only set value but i seems that my value will bind. Anyone know anything else i can use? I can get it to work with @Bind-Value in input fields but not in dropdowns.
My dropdown list:
<div class="row">
<div class="mb-1">
<label class="form-label col-5 col-md-4 text-end">Numbers:</label>
<select class="mr-2">
@foreach (var item in number_list)
{
<option @bind-value="@Numbers" size="15">@item.Numbers</option>
Number = item.Number.ToString();
}
</select>
</div>
</div>
Myproperty i would like to bind to
[Parameter] public string? Numbers{ get; set; }
Worth noting is that Number is a float value in my list that i loop through in my foreach number_list
2
Answers
your select should look like this instead:
when drop down index changes it will update @Numbers
im assuming this is what you wanted?
Actually, Josh pretty much nailed it already.
The binding of the selected value must be in the "select" tag using the @bind attribute, while the value of the subsequent options is set with the "value" attribute in the "option" attribute.
Below is the entire code: