There are three groups of radio buttons on my page and I want to submit each of their values with one button.
<table>
<tr>
<td>
@Html.RadioButton("rating1", "yes", true) Yes
@Html.RadioButton("rating1", "no", false) No
@Html.RadioButton("rating1", "maybe", false) Maybe
</td>
</tr>
<tr>
<td>
@Html.RadioButton("rating2", "yes", true) Yes
@Html.RadioButton("rating2", "no", false) No
@Html.RadioButton("rating2", "maybe", false) Maybe
</td>
</tr>
<tr>
<td>
@Html.RadioButton("rating3", "yes", true) Yes
@Html.RadioButton("rating3", "no", false) No
@Html.RadioButton("rating3", "maybe", false) Maybe
</td>
</tr>
</table>
I want to send a dictionary as a parameter to the controller action so I can retrieve the values for each rating.
The controller looks like this:
public ActionResult Rate(Guid uniqueId, Dictionary<Guid, string> ratings)
{
[...]
}
I have tried:
<input type="submit" value="Send Ratings" onclick="@Url.Action("Rate", "Controller", new {new Dictionary<string,string> {{"rating1", "yes"}, {"rating2", "no"}, {"rating3", "maybe"}})"></input>
but passing a Dictionary as a RouteValue like that is not allowed.
How do I send all 3 radio button [name,value] pairs to the action with one button /submit? Also, should all three groups be in the same form or separate forms?
I am open to using javascript, but would prefer using Razor HTML helpers.
Thanks