我有一个绑定到 CheckBoxFor 或 EditorFor (任一)的布尔值。
这是模型声明:
公共布尔 IsActive { 获取;放; }
这是 html(如您所见,我尝试了多种变体):
<div>
@*@Html.CheckBoxFor(model => model.IsActive, new { htmlAttributes = new { @class = "form-control" } )*@
@*@Html.CheckBoxFor(model => model.IsActive)*@
@*@Html.EditorFor(model => model.IsActive, new { htmlAttributes = new { @class = "form-control" } })*@
@Html.EditorFor(model => model.IsActive)
</div>
我似乎有一个副作用,即每当我选中该框时,表单中的 IsActive 值都会重复。我在发布之前提醒序列化,这就是选中该框时的样子:
...&IsActive=真&IsActive=假...
当未选中该框时,它只是 ...&IsActive=false...
什么可能导致这种行为?TIA