[英]MVC Razor .CheckboxFor not binded as expected
I've tried both CheckboxFor and EditorFor to bind a checkbox to the model. 我已经尝试了CheckboxFor和EditorFor来将复选框绑定到模型。 The issue is that it's always unchecked and it does not seem to reflect the true/false value from the model. 问题在于它始终处于未选中状态,并且似乎无法反映模型中的true / false值。
View 视图
@Html.CheckBoxFor(x => x.IsConfirmed)
Result in browser 在浏览器中的结果
<input name="IsConfirmed" id="IsConfirmed" type="checkbox" value="true"/>
<input name="IsConfirmed" type="hidden" value="false"/>
View 视图
@Html.EditorFor(x => x.IsConfirmed)
Result in browser 在浏览器中的结果
<input name="IsConfirmed" class="check-box" id="IsConfirmed" type="checkbox" data-val="true" value="true"/>
<input name="IsConfirmed" type="hidden" value="false"/>
What am I missing? 我想念什么?
As @musefan commented, the issue is with my view and not the HtmlHelper. 正如@musefan所说,问题出在我的观点上,而不是HtmlHelper。
The issue boiled down to "chain-of-events". 问题归结为“事件链”。 The view was binded post-load by ajax, and the value for the checkbox was not set up for this call. 该视图在加载后由ajax绑定,并且未为此调用设置复选框的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.