创建页面 进行初始化 默认 男 被选中
- <div class="label">
- <div class="editor-label">
- @Html.LabelFor(model => model.Sex)
- </div>
- <div class="radios">
- <label id="boy"> @Html.RadioButtonFor(model => model.Sex,"男", new { @id="boy",@name="sex",@checked=true})男</label>
- <label id="gril"> @Html.RadioButtonFor(model => model.Sex, "女", new { @id="gril",@name="sex"})女</label>
- </div>
- </div>
编辑页面 编辑时,绑定值,根据数据显示 RadioButtonFor自动选中状态
- <div class="label">
- <div class="editor-label">
- @Html.LabelFor(model => model.Sex)
- </div>
- <div class="radios">
- <label id="boy"> @Html.RadioButtonFor(model => model.Sex,"男", new { @id="boy",@name="sex",@checked=true})男</label>
- <label id="gril"> @Html.RadioButtonFor(model => model.Sex, "女", new { @id="gril",@name="sex"})女</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>