12 .net c# asp.net-mvc-4
我有三个单选按钮,我的字段值类型是整数,如Maintenance for 3,Active for 1和Inactive for 2.
@Html.RadioButtonFor(model => model.StatusId, "3") Maintenance
@if (Model.IsReady == true)
{
<span> @Html.RadioButtonFor(model => model.StatusId,"1") Active</span>
}
@Html.RadioButtonFor(model => model.StatusId, "2") Inactive
Run Code Online (Sandbox Code Playgroud)
我使用上面的代码,然后正确插入数据,但当我的表单在编辑模式下打开,然后我没有选择任何单选按钮.
我也使用下面的代码,但没有成功.
@Html.RadioButtonFor(model => model.StatusId, "3", Model.StatusId == '3' ? new {Checked = "checked"} : null) Maintenance
@if (Model.IsReady == true)
{
<span> @Html.RadioButtonFor(model => model.StatusId, "1",Model.StatusId == '1' ? new {Checked = "checked"} : null) Active</span>
}
@Html.RadioButtonFor(model => model.StatusId, "2",Model.StatusId == '2' ? new {Checked = "checked"} : null) Inactive
Run Code Online (Sandbox Code Playgroud)
所以如何在编辑模式下选择单选按钮
提前致谢
mat*_*410 22
我创建radiobuttons的方式如下:
@Html.RadioButtonFor(model => model.StatusId,3,new { id = "rbMaintenance" })
@Html.Label("rbMaintenance","Maintenance")
@Html.RadioButtonFor(model => model.StatusId,2,new { id = "rbInactive" })
@Html.Label("rbInactive","Inactive")
@Html.RadioButtonFor(model => model.StatusId,1,new { id = "rbActive" })
@Html.Label("rbActive","Active")
Run Code Online (Sandbox Code Playgroud)
与您的代码的不同之处在于,当您的StatusId类型为Int时,您应该将RadioButtonFor中的值作为整数输入,例如3表示维护而不是"3".