Asp.net mvc 如何在razor中选择Radio按钮

Asp.net mvc 如何在razor中选择Radio按钮,asp.net-mvc,asp.net-mvc-4,c#-4.0,razor,Asp.net Mvc,Asp.net Mvc 4,C# 4.0,Razor,我有三个单选按钮,我的字段值类型是整数类似于3的维护, 1处于活动状态,2处于非活动状态 @Html.RadioButtonFor(model => model.StatusId, "3") Maintenance @Html.RadioButtonFor(model => model.StatusId,"1") Active @Html.RadioButtonFor(model => model.StatusId, "2") Inactive

我有三个单选按钮,我的字段值类型是整数类似于3的维护, 1处于活动状态,2处于非活动状态

     @Html.RadioButtonFor(model => model.StatusId, "3") Maintenance
     @Html.RadioButtonFor(model => model.StatusId,"1") Active
     @Html.RadioButtonFor(model => model.StatusId, "2") Inactive
我使用上述代码,然后正确插入数据,但当我的表单在编辑模式下打开时,我没有选择任何单选按钮

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

  @Html.RadioButtonFor(model => model.StatusId, "3", Model.StatusId == '3' ? new {Checked = "checked"} : null) Maintenance
  @Html.RadioButtonFor(model => model.StatusId, "1",Model.StatusId == '1' ? new {Checked = "checked"} : null) Active}
  @Html.RadioButtonFor(model => model.StatusId, "2",Model.StatusId == '2' ? new {Checked = "checked"} : null) Inactive
那么如何在编辑模式下获得选中的单选按钮呢


提前感谢

我在帖子中的解决方案将适用于您。使用
Model.StatusId==“3”
比较来确定扩展方法中的“checked”值。

请使用下面的代码段进行尝试

@Html.RadioButtonFor(model => model.StatusId, "2", Model.StatusId == '2' ? new {@Checked = "checked"} : '') 


如果上述代码不可用,请提供此radiobutton/输入的呈现html代码。

请检查下面的链接,可能会对您有所帮助

@Html.RadioButtonFor(model => model.StatusId, "2", Model.StatusId == '2' ? new {@Checked = "checked"} : null)