user3661407
user3661407

Reputation: 543

How do I get selected radiobutton value in controller?

I am using mvc.I am unable to get radio button value in controller.

 @Html.RadioButtonFor(model => model.SelecetdOption, m.Name, new {});

Upvotes: 0

Views: 5754

Answers (1)

Josh Blade
Josh Blade

Reputation: 981

You can have something like this in your view:

<input type="radio" id="rbOption1" name="rbMyChoices" value="Option1" />
<input type="radio" id="rbOption2" name="rbMyChoices" value="Option2" />

and then in your controller...

public actionresult MyAction(string rbMyChoices){
    if(rbDents == "Option1")...
    if(rbDents == "Option2")...
}

If you add rbMyChoices to your controller parameters, it will contain the selected Value of the rbMyChoices rbgroup.

Upvotes: 1

Related Questions