I am not able to set the default radio button to "Checked" ! I am using @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>
Is it possible to set a radio button as cheched using @Html.RadioButtonFor ?
Thx
In your controller action set the value of the UserType
property on your view model to the corresponding value:
public ActionResult SomeAction()
{
MyViewModel model = ...
// preselect the second radio button
model.UserType = "type2";
return View(model);
}
and in your view:
<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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With