我有三个单选按钮,我的字段值类型是整型,如维护3、活动1和非活动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我使用上面的代码,然后正确地插入数据,但是当我的表单在编辑模式下打开时,我没有选择任何单选按钮。
我也使用了下面的代码,但没有成功。
@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那么如何在编辑模式下获得选中的单选按钮呢?
提前感谢
发布于 2014-05-08 07:18:58
我制作无线电按钮的方式如下:
@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")代码的不同之处在于,由于您的StatusId类型是Int,所以您应该将RadioButtonFor中的值作为整数输入,例如,用于维护而不是'3‘。
https://stackoverflow.com/questions/23534642
复制相似问题