如果使用 Blazor 框架检查复选框值,我试图找到它,但到目前为止我找不到任何方法。当我将绑定(bind)放在复选框中时,它总是被选中。我无法弄清楚如何获得检查值。
这是我的代码:
<input type="checkbox" id="addition" name="math" value="add" bind="@name" />
<label for="addition">Addition</label>
最佳答案
将复选框值绑定(bind)到 bool 值。
在您的@Code 中,bool checkedValue = false;//如果适合您的用例,则为 true
在您的 HTML 中:
<input type="checkbox" checked @bind="checkedValue">
checkedValue 的值将与您的复选框具有相同的值。
关于c# - .NET Core Blazor : How to get the Checkbox value if it is checked?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51234654/