根据该值使复选框处于选中状态还是未选中状态? [英] Make a checkbox checked or unchecked based on the value?

查看:88
本文介绍了根据该值使复选框处于选中状态还是未选中状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何基于该值以编程方式使复选框处于选中状态或未选中状态?也就是说,对于特定用户,如果该值为true,则应该选中该复选框;否则,如果该值为false,则需要取消选中该复选框.我通过以下方式声明了该复选框:

How can we make a checkbox checked or unchecked programatically based on the value? That is to say, for a particular user if the value is true, the checkbox should be checked, else if the value is false the checkbox needs to be unchecked. I declared the checkbox in the following way:

<input type="checkbox" class="checkbox">

推荐答案

if(condition = true)
{
@Html.CheckBoxFor(x => x.Test, new { @checked = "checked" })
}
else
{
@Html.CheckBoxFor(x => x.Test)
}

希望这会有所帮助:)

这篇关于根据该值使复选框处于选中状态还是未选中状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆