我尝试使用 Blazor wasm 绑定单选按钮@bind
。但尝试失败,也找不到相关文档。
我在此文档链接中搜索 - https://learn.microsoft.com/en-us/aspnet/core/blazor/components/data-binding?view=aspnetcore-9.0
代码:
<div class="control flex flex-col">
<label class="radio">
<input type="radio" name="stock" @bind="Filter.InStock" checked="@(Filter.InStock.HasValue && Filter.InStock.Value)" @bind:after="LoadData" />
In Stock
</label>
<label class="radio">
<input type="radio" name="stock" @bind="Filter.OutOfStock" checked="@(Filter.OutOfStock.HasValue && Filter.OutOfStock.Value)" @bind:after="LoadData" />
Out of Stock
</label>
</div>
@code {
public class StockFilter
{
public bool? InStock { get; set; }
public bool? OutOfStock { get; set; }
}
public StockFilter Filter = new();
public void LoadData()
{
Console.WriteLine("In" + Filter.InStock);
Console.WriteLine("Out" + Filter.OutOfStock);
// make API call
}
}
控制台日志:
请您帮助我或者指出正确的文档链接?