【发布时间】:2014-04-10 21:39:28
【问题描述】:
我正在调用一个控制器的操作方法,它返回一个布尔值。基于这个 bool 输出,我在 UI 中选中/取消选中一个复选框。这工作正常,直到我查看未选中复选框值的记录。在此之后,所有记录都将复选框显示为未选中,即使输出为 true,并且控件正确呈现,选中的属性设置为“已选中”。
$.ajax({
url: '@Url.Action("IsUserActive", "Account")',
cache: false,
type: 'POST',
data: { userName: data.UserName },
success: function (output) {
if(output == "True")
$("#isActive").attr("checked", true);
else
$("#isActive").attr("checked", false);
$("#pwdResetModal").modal('show');
}
});
@using (Html.BeginForm("ResetPassword", "Account"))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary()
<fieldset>
<legend>Registration Form</legend>
<ol>
<li>
@Html.HiddenFor(m => m.UserName, new { id = "userName" })
@Html.LabelFor(m => m.IsActive)
@Html.CheckBoxFor(m => m.IsActive,new { id = "isActive" })
</li>
</ol>
</fieldset>
<button class="btn btn-info">Submit</button>
}
【问题讨论】:
标签: jquery asp.net-mvc-4 checkbox html-helper