有没有办法使用Blazorise中的从列表中选择默认值?现在默认值是null,但我希望它是"3“。
<Select @bind-SelectedValue="@_someProperty">
@foreach (string number in _numbers)
{
<SelectItem Value="@number ">@number </SelectItem>
}
</Select>
@code
private static readonly string[] _numbers =
{
"1", "2", "3", "4", "5",
};发布于 2020-06-14 01:23:39
这是一个解决这个问题的简单方法(只需添加一个具有初始值的变量)。您还可以使用SelectedValueChanged手动处理您的自定义变量。
<Select @bind-SelectedValue="@_selectedProperty" SelectedValueChanged="@OnSelectedValueChanged">
@foreach (string number in _numbers)
{
<SelectItem Value="@number ">@number </SelectItem>
}
</Select>
@code
{
private string _selectedProperty = 3;
private static readonly string[] _numbers =
{
"1", "2", "3", "4", "5",
};
void OnSelectedValueChanged( string value )
{
_selectedProperty = value; // Bind to the custom variable
Console.WriteLine( selectedValue ); // Write in Console Just for Checking
}
}https://stackoverflow.com/questions/61937418
复制相似问题