If your Vote controller accepts a parameter 'string radname' the value 'goodbye' will be passed to it when you select submit if the top radio button was selected.
Remember the first parameter of Html.RadioButton is "name" which is not the title of it but the name attribute on the <input> tag.
shapper
Contributor
3932 Points
3789 Posts
RadioButton and Form
Oct 08, 2008 01:33 AM|LINK
Hello,
I am rendering a poll as follows:
<% using (Html.Form p.Vote(), FormMethod.Post)) { %> <fieldset> <legend><%= ViewData.Get</legend> <ol> <% foreach (OptionPaper paper in ViewData.Get <li> <%= Html.RadioButton(paper.Option.Answer, paper.Option.OptionID.ToString(), false, new { @class ="Radio" }); %> </li> <% } %> </ol> </fieldset> <fieldset class="Action"> <%= Html.SubmitButton("Submit", "Vote", new { title ="Vote", @class ="Submit" })%> </fieldset> <% } %>I need to pass the selected radio value, which paper.Option.OptionID, in p.Vote(...) when the form is submited.How can I do this?
Note: I am using RadioButton instead of RadioButtomList because I want to rendered it inside a list.
Thanks,
Miguel
schotime
Member
3 Points
17 Posts
Re: RadioButton and Form
Oct 08, 2008 04:57 AM|LINK
Html.RadioButton("radname", "goodbye", false)
Html.RadioButton("radname", "hello", false)
If your Vote controller accepts a parameter 'string radname' the value 'goodbye' will be passed to it when you select submit if the top radio button was selected.
Remember the first parameter of Html.RadioButton is "name" which is not the title of it but the name attribute on the <input> tag.