如何在剃刀视图中设置复选框? [英] How do I set a checkbox in razor view?
本文介绍了如何在剃刀视图中设置复选框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要默认选中一个复选框:
I need to check a checkbox by default:
我尝试了所有这些,没有检查我的复选框 -
I tried all of these, nothing is checking my checkbox -
@Html.CheckBoxFor(m => m.AllowRating, new { @value = "true" })
@Html.CheckBoxFor(m => m.AllowRating, new { @checked = "true" })
@Html.CheckBoxFor(m => m.AllowRating, new { @checked = true })
@Html.CheckBoxFor(m => m.AllowRating, new { @checked = "checked"})
推荐答案
您应该将 AllowRating
属性设置为 true
,最好是在控制器或模型中.
与其他输入一样,复选框的状态反映了属性的值.
You should set the AllowRating
property to true
, preferably in the controller or model.
Like other inputs, the checkbox's state reflects the value of the property.
这篇关于如何在剃刀视图中设置复选框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文