gpt4 book ai didi

asp.net-mvc - 默认情况下将@Html.RadioButtonFor 设置为选中

转载 作者:行者123 更新时间:2023-12-04 19:13:41 25 4
gpt4 key购买 nike

我无法将默认单选按钮设置为“已检查”!
我正在使用 @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 设置单选按钮作为检查?

谢谢

最佳答案

在您的 Controller 操作中设置 UserType 的值将 View 模型上的属性设置为相应的值:

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>

关于asp.net-mvc - 默认情况下将@Html.RadioButtonFor 设置为选中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12437563/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com