创建页面 进行初始化 默认 男 被选中
@Html.LabelFor(model => model.Sex)
</div>
<div class="radios">
@Html.RadioButtonFor(model => model.Sex, 1, new { @id="radio1",@name="sex",@checked=true})<label id="boy">男</label>
@Html.RadioButtonFor(model => model.Sex, 2, new { @id="radio2",@name="sex"})<label id="gril">女</label>
</div>
</div>
编辑页面 编辑时,绑定值,根据数据显示 RadioButtonFor自动选中状态
<div class="label">
<div class="editor-label">
@Html.LabelFor(model => model.Sex)
</div>
<div class="radios">
@Html.RadioButtonFor(model => model.Sex, 1, new { @id="radio1",@name="sex"})<label id="boy">男</label>
@Html.RadioButtonFor(model => model.Sex, 2, new { @id="radio2",@name="sex"})<label id="gril">女</label>
</div>
</div>
model.Sex是int 也可以是bool sex值是1时 男被选中 2时女被选中
<div class="label">
<div class="editor-label">
@Html.LabelFor(model => model.Activity)
</div>
<div class="radios">
@Html.RadioButtonFor(model => model.Activity, true, new { @id = "radio3", @name = "Activity" })<label id="tr">启用</label>
@Html.RadioButtonFor(model => model.Activity, false, new { @id = "radio4", @name = "Activity" })<label id="fl">禁用</label>
</div>
</div>
model.Activity是bool