这是我的代码:
_testPartial.cshtml(部分视图)
@Html.RadioButtonFor(model => model.CardType, "G", new { @checked = @Model.IsGold})
@Html.RadioButtonFor(model => model.CardType, "P", new { @checked = @Model.IsPlatinum})
@Html.RadioButtonFor(model => model.CardType, "B", new { @checked = @Model.IsBusiness})控制器
public PartialViewResult ShowCardtype()
{
Model cardType= new Model {
IsGold=true,
IsPlatinum=false,
IsBusiness=false};
return PartialView("_testPartial",cardType);
}预期的行为是,黄金单选按钮选项应该在表单中被选中。但它总是选择最后一个选项。我试着返回“选中”字符串,但没有运气。感谢你的帮助。
发布于 2014-01-29 14:56:44
第二个选项是选择的选项,您不需要新的部分。
@Html.RadioButtonFor(model => model.CardType, "G")
@Html.RadioButtonFor(model => model.CardType, "P")
@Html.RadioButtonFor(model => model.CardType, "B")加载视图时,将model.CardType设置为G、P或B,它将选择正确的单选按钮
https://stackoverflow.com/questions/21434540
复制相似问题