Blazor 将复选框绑定到具有条件值的字段

Blazor 将复选框绑定到具有条件值的字段,blazor,blazor-server-side,Blazor,Blazor Server Side,我有一个Blazor应用程序,其中有三个复选框,用来指示是否应该创建、修改或删除某个用户帐户 <input id="CreationCheckbox" type="checkbox" @bind="req.FkRequestType" /> <input id="ModificationCheckbox" type="checkbox" @bind="req.FkRequestType"/> <input id="RemovalCheck

我有一个Blazor应用程序,其中有三个复选框,用来指示是否应该创建、修改或删除某个用户帐户

    <input id="CreationCheckbox" type="checkbox" @bind="req.FkRequestType" />

    <input id="ModificationCheckbox" type="checkbox" @bind="req.FkRequestType"/>

    <input id="RemovalCheckbox" type="checkbox" @bind="req.FkRequestType"/>

@code {
    Request req = new Request();
}
我想将值1(创建)、值2(修改)或值3(删除)绑定到FkRequestType字段,具体取决于激活的复选框。当然,对于上面的代码,如果勾选其中一个复选框,绑定将始终导致“1”

我试过了,但没有编译:

<input id="CreationCheckbox" type="checkbox" @bind="req.FkRequestType == 1 ? 1 : 0" />
<input id="ModificationCheckbox" type="checkbox" @bind="req.FkRequestType == 1 ? 2 : 0" />
<input id="RemovalCheckbox" type="checkbox" @bind="req.FkRequestType == 1 ? 3 : 0" />


你是否考虑使用收音机而不是复选框?另外,
@bind
用于“双向”绑定,您应该在这里使用
@onclick=“@(()=>select(1))”
+
checked=“@(req.FkRequestType==1)
。查找同意的单选复选框,而不是复选框。否则,如果用户复选框有多个复选框,会发生什么情况?我已切换到单选按钮,这确实是更好的选择。我已经有一个功能,当您单击一个复选框时,其他复选框将被禁用。但是使用上面dani herrera的代码,“选择”按钮无法识别关键字:“选择的名称在当前上下文中不存在”
<input id="CreationCheckbox" type="checkbox" @bind="req.FkRequestType == 1 ? 1 : 0" />
<input id="ModificationCheckbox" type="checkbox" @bind="req.FkRequestType == 1 ? 2 : 0" />
<input id="RemovalCheckbox" type="checkbox" @bind="req.FkRequestType == 1 ? 3 : 0" />