1

在我的编辑视图中,我可以保留字段的值,但单选按钮。就像我从网格中选择行并单击编辑一样,它为我提供了以前保存的所有其他字段 bt 的值,而不是单选按钮

如果保存的数据包含性别值为 F 那么我如何设置这些值

if(gender='f')
 {
    <input type="radio" name="forwhom" value="f" checked="checked"></input>
 }
else
  <input type="radio" name="forwhom" value="m" checked="checked"></input>

我正在使用 2 个部分视图显示我的数据,如下所示

我必须为它写任何ajax吗?请帮忙问候!!!

4

2 回答 2

1

在这种情况下,您可以使用Razor :

@Html.RadioButtonFor(x => x.Gender, "radioValue", new { @checked = true })

更多关于它的信息:

如何在 Asp.net MVC3 中将 Html.RadioButtonFor 设置为默认选中

于 2012-04-27T00:29:39.470 回答
-1

或试试这个。

if(gender = 'f')
 {
    @Html.RadioButtonFor(x => x.Gender, "radioValue", new { @checked = "true"})
 }
else 
 {
    @Html.RadioButtonFor(x => x.Gender, "radioValue", new {@checked = "true"})      
 }

希望能帮到你。。谢谢。

于 2013-08-30T07:45:08.970 回答