C# Mvc Razor语法中的RadioButton

C# Mvc Razor语法中的RadioButton,c#,.net,asp.net-mvc-4,C#,.net,Asp.net Mvc 4,我有三个单选按钮,我的字段值类型是整数类似于3的维护, 1处于活动状态,2处于非活动状态 @Html.RadioButtonFor(model => model.StatusId, "3") Maintenance @if (Model.IsReady == true) { <span> @Html.RadioButtonFor(model => model.StatusId,"1") Active</span> } @Html.RadioButton

我有三个单选按钮,我的字段值类型是整数类似于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.radiobutton(model=>model.StatusId,“3”)维护
@如果(Model.IsReady==true)
{
@Html.radioButton(model=>model.StatusId,“1”)处于活动状态
}
@Html.radioButton(model=>model.StatusId,“2”)处于非活动状态
我使用上述代码,然后正确插入数据,但当我的表单在编辑模式下打开时,我没有选择任何单选按钮

我也使用了下面的代码,但没有成功

@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
@Html.radiobutton(model=>model.StatusId,“3”,model.StatusId==“3”?新的{Checked=“Checked”}:null)维护
@如果(Model.IsReady==true)
{
@Html.radioButton(model=>model.StatusId,“1”,model.StatusId==“1”?新的{Checked=“Checked”}:null)处于活动状态
}
@Html.radioButton(model=>model.StatusId,“2”,model.StatusId==“2”?新的{Checked=“Checked”}:null)未激活
那么如何在编辑模式下获得选中的单选按钮呢


提前感谢

我创建单选按钮的方式如下:

@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,因此您应该在RadioButton中输入值作为整数,例如用于维护的值为3,而不是“3”