我无法将默认单选按钮设置为“已选中”!我使用的是@Html.RadioButtonFor:
<div id="private-user">
@Html.RadioButtonFor(m => m.UserType, "type1", new { @class="type-radio" , **@Checked="checked"** }) 1
</div>
<div id="proff-user">
@Html.RadioButtonFor(m => m.UserType, "type2", new { @class="type-radio" }) 2
</div>是否可以使用@Html.RadioButtonFor将单选按钮设置为选中状态?
Thx
发布于 2012-09-15 21:20:20
发布于 2012-09-15 23:36:50
在您的控制器操作中,将视图模型的UserType属性的值设置为相应的值:
public ActionResult SomeAction()
{
MyViewModel model = ...
// preselect the second radio button
model.UserType = "type2";
return View(model);
}在你看来:
<div id="private-user">
@Html.RadioButtonFor(m => m.UserType, "type1", new { @class="type-radio" }) 1
</div>
<div id="proff-user">
@Html.RadioButtonFor(m => m.UserType, "type2", new { @class="type-radio" }) 2
</div>发布于 2012-09-15 21:34:31
看看这篇文章,他们已经回答了你的问题(虽然是MVC 2,但在这里是一样的):
How to Set RadioButtonFor() in ASp.net MVC 2 as Checked by default
希望这能有所帮助
https://stackoverflow.com/questions/12437563
复制相似问题