我有一个剃刀RadioButtonFor,我试图默认检查,但没有任何工作。以下是我的代码:
@Html.RadioButtonFor(m=>m.selected, new {@checked=true});其中selected是一个布尔值。和生成的Html:
<input name="selected" id="selected" type="radio"
value="{ Name = groupRadio, checked = True }">我也试过
@Html.RadioButtonFor(m=>m.selected, 0, new {@checked=true});这也不管用。有什么想法吗?
谢谢
发布于 2017-08-17 17:05:43
如果selected为bool,则您的单选按钮需要为
<label>
@Html.RadioButtonFor(m=>m.selected, true, new { id = "" });
<span>Yes</span>
</label>
<label>
@Html.RadioButtonFor(m=>m.selected, false, new { id = "" });
<span>No</span>
</label>注第二个参数生成绑定到bool属性的value属性。
如果selected的值为true,则选择第一个,否则选择第二个
https://stackoverflow.com/questions/45730787
复制相似问题