Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8907855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:01:24+00:00 2026-06-15T03:01:24+00:00

I have an MVC3 Internet Application. Basically it has a registration form, which has

  • 0

I have an MVC3 Internet Application.

Basically it has a registration form, which has 3 radio buttons on it. Whenever i check one of the radio button and hit submit button, it should go to the controller and insert data into my database.

I also have validations to the fields in my Registration form.

Somewhere in stackoverflow, i’ve read that Property names in the Model and the Names of the fields in the view have to be matched inorder to preserve the values in the form even after the validation errors.

This statement works perfectly for TextBoxes and for Dropdownlists.

My Question is : How to have distinct name foreach radiobutton ?

As I’ve said my form has 3 radio buttons.

Say,These are the TextBoxes followed by radio buttons

Phone 1 // here is the radio button1
Phone 2 // here is the radio button2
Phone 3 // here is the radio button3

In my model i’ve

public string Phone1 { get; set; }
public string Phone2 { get; set; }
public string Phone3 { get; set; }
//also i have a preferred phone--which sets if any of the phone is selected
public bool PreferredPhone { get; set; }

I’ve tried something like this

Phone1:
@Html.RadioButtonFor(model => model.PreferredPhone, Model.Phone1, new { id = "Phone1", @onclick = "PrefferedPhone(this)" })
Phone2:
@Html.RadioButtonFor(model => model.PreferredPhone, Model.Phone2, new { id = "Phone2", @onclick = "PrefferedPhone(this)" })
Phone3:
@Html.RadioButtonFor(model => model.PreferredPhone, Model.Phone3, new { id = "Phone3", @onclick = "PrefferedPhone(this)" })

but this declaration sets the name of all the radio buttons to PreferredPhone

How to have a different name for each Radio Button ?

Even i tried by keeping RadioButton names as model=>model.Phone1,model=>model.Phone2,model=>model.Phone3, but if i set like this i can be able to select all the three radio buttons.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:01:25+00:00Added an answer on June 15, 2026 at 3:01 am

    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).

    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:

    @Html.RadioButton("stuffRadio", 1)
    @Html.RadioButton("stuffRadio", 2)
    @Html.RadioButton("stuffRadio", 3)
    @Html.RadioButton("stuffRadio", 4)
    

    And then in the controller when the form has been posted:

    [HttpPost]
    public ActionResult TheAction(Model model, string stuffRadio)
    {
        //dostuff to model and other things
        string value = stuffRadio;
        //dostuff to the selected radioStuff :)
    }
    

    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?

    Using my own example I would simply do something like this:

    @Html.RadioButton("stuffRadioGroup1", 1)
    @Html.RadioButton("stuffRadioGroup2", 2)
    @Html.RadioButton("stuffRadioGroup3", 3)
    @Html.RadioButton("stuffRadioGroup4", 4)
    

    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:

    [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 :)
    }
    

    Again, may I´m misunderstang and then you of course correct me 😉
    Later!

    ########## EDITED ###################

    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:

    @(Html.BeginForm("SomeAction", "Controller")
    {
        <input type="hidden" name="derp" value="1234" />
        @Html.RadioButtonFor(model => model.PreferredPhone, Model.Phone3, new { id = "Phone3", @onclick = "PrefferedPhone(this)" })
        <button type="submit">submit</button>
    }
    

    If that hidden field is supposed to be pass as well, the controller should be something like this:

    [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);
        }
    }
    

    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)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an MVC3 webapplication which runs as a DOMAIN\USER1 account. This user has
I have mvc3 web app. inside that I have one Enquiry form once I
I have an MVC3 application that has a custom HandleErrorAttribute so that I can
I have a mvc3 web application which uses jqgrid extensively. I just came to
I have an MVC3 and EF 4 Code First application, which is configured to
I have a mvc3 Ajax.BeginForm. Instead of clicking on the button I would like
I have a MVC3 ASP.NET Project in which I am using jQuery and KendoUI
I have an MVC3 program in which I want to query a database and
I have a MVC3 application with some XML files on the App_Data folder. To
I have MVC3 web application running under IIS 7. During initialization in global.asax application

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.