Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When you talk about selecting all three radio buttons then it sound like your are talking about them as if they were checkboxes. The radio buttons that are considered in the same group can´t be all selected at the same time, only one selected per group (but perhaps you already know that and I´m misunderstanding).</p> <p>From what you read somewhere in Stackoverflow that is correct that Property names in the Model and the Names of the fields in the view have to be matched. Fore instance if you have radiobuttons in a view like this: </p> <pre><code>@Html.RadioButton("stuffRadio", 1) @Html.RadioButton("stuffRadio", 2) @Html.RadioButton("stuffRadio", 3) @Html.RadioButton("stuffRadio", 4) </code></pre> <p>And then in the controller when the form has been posted:</p> <pre><code>[HttpPost] public ActionResult TheAction(Model model, string stuffRadio) { //dostuff to model and other things string value = stuffRadio; //dostuff to the selected radioStuff :) } </code></pre> <p>Anyway, if I´m misunderstang then I want to ask you in return. You say you want to distinct each radiobutton, I´m not quite sure why. Is so you can get all the phone-numbers on the post action and into the controller?</p> <p>Using my own example I would simply do something like this:</p> <pre><code>@Html.RadioButton("stuffRadioGroup1", 1) @Html.RadioButton("stuffRadioGroup2", 2) @Html.RadioButton("stuffRadioGroup3", 3) @Html.RadioButton("stuffRadioGroup4", 4) </code></pre> <p>But then again if I would want to read all thos group selections I would of course have to do the same thing with the parameters into the controller like this:</p> <pre><code>[HttpPost] public ActionResult TheAction(Model model, string stuffRadioGroup1, string stuffRadioGroup2, string stuffRadioGroup3, string stuffRadioGroup4) { //dostuff to model and other things string value1 = stuffRadioGroup1; string value2 = stuffRadioGroup2; string value3 = stuffRadioGroup3; string value4 = stuffRadioGroup4; //dostuff to the selected radioStuff :) } </code></pre> <p>Again, may I´m misunderstang and then you of course correct me ;) Later!</p> <p><strong>########## EDITED ###################</strong></p> <p>First of all, if you want hidden fields to be submitted they have to be within the form, and the name of that particular hidden field has to be passed as parameter into the controller with the same name. For instance:</p> <pre><code>@(Html.BeginForm("SomeAction", "Controller") { &lt;input type="hidden" name="derp" value="1234" /&gt; @Html.RadioButtonFor(model =&gt; model.PreferredPhone, Model.Phone3, new { id = "Phone3", @onclick = "PrefferedPhone(this)" }) &lt;button type="submit"&gt;submit&lt;/button&gt; } </code></pre> <p>If that hidden field is supposed to be pass as well, the controller should be something like this:</p> <pre><code>[HttpPost] public ActionResult SomeAction(Model mymodel, string derp, FormCollection collection) { int number = Convert.toInt32(derp); //now number should be '1234' string phone3 = collection.Get("Phone3"); //now you have the phone number and the hidden field telling you if that number is preffered TryUpdateModel(mymodel); //populate the model if it hasn´t already been populated if(ModelState.IsValid) { //do stuff else { //TODO: here you should set the model with the stuff from derp and collection before returning return View("SameViewAsBefore", mymodel); } } </code></pre> <p>As you can see I put FormCollection in there, just to have a different approach. Hope this helps, if not, you can always ask again :) (I´m known to misunderstand things sometimes)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload