Set @ Html.RadioButtonFor Default Validation

I cannot set the default switch to "Verified"! 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 the switch using @ Html.RadioButtonFor?

thank

+5
source share
4 answers

In the action of your controller, set the property value UserTypein your view model to the appropriate value:

public ActionResult SomeAction()
{
    MyViewModel model = ...

    // preselect the second radio button
    model.UserType = "type2";
    return View(model);
}

and in your opinion:

<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>
+5
0

.

public YourViewModel(){
    UserType = "type1";
}

, , , .

0

All Articles