locked
How to add a radio button in mvc 5 view RRS feed

  • Question

  • Hi Everyone, m really a new to c# MVC. If anyone can help me point out how to add  radio buttons in the following program fragment. I wanna have male and female options for the user, and in the back end I use bool type for "Gender". Thanks for any advise and help in advance ^.^
    View 

    <div class="form-group"> @Html.LabelFor(model => model.Gender, new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.EditorFor(model => model.Gender) @Html.ValidationMessageFor(model => model.Gender) </div> </div>

    Model

    public bool Gender { get; set; }


    • Moved by Eason_H Thursday, November 21, 2013 7:11 AM
    Wednesday, November 20, 2013 5:33 AM

Answers

All replies

  • Try in the MVC forum http://forums.asp.net/1146.aspx

    Paul Linton

    • Proposed as answer by Eason_H Thursday, November 21, 2013 7:11 AM
    • Marked as answer by Just Karl Wednesday, December 11, 2013 11:43 PM
    Wednesday, November 20, 2013 5:39 AM
  • Hi mizuluffy:

    No radiobutton directly offered to you as far as I see, you can use CheckBox instead (Checked for male, unchecked for female)


    ASP.NET Questions
    Other Discussions
    FreeRice Donate
    Issues to report

    Wednesday, November 20, 2013 5:48 AM
  • thank you very much, may be I can not use radio button directly. Thank you very much
    Wednesday, November 20, 2013 9:58 PM
  • This looks like ASP Code. You are better of asking ASP Question in the ASP.Net Forum:

    http://forums.asp.net/

    Your backend might have to deal with a third case: Undefinied. As long as no gender has been selected, that is the state the Property should be in.
    You could use nullable bool instead of bool and take null as value for undefined.

    Radiobuttons don't help much if they come alone. They only work if you have groups of 2 or more. If you want a single RadioButton, you want a Checkbox.
    And you actually need to tell the Display System wich radio buttons belong to wich mutual exclusion group. Try googling for "[Your Dispaly System] radio button group". You should find some answers.


    Let's talk about MVVM: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b1a8bf14-4acd-4d77-9df8-bdb95b02dbe2 Please mark post as helpfull and answers respectively.

    Wednesday, November 20, 2013 11:33 PM
  • "No radiobutton directly offered "

    Really?  Do you think that ASP.Net MVC V5 does not allow radio buttons in the UI?  Why would you think this?

    =====

    "This looks like ASP Code"

    No it doesn't.  It is quite obviously razor syntax in MVC.  (The big hint is that the OP said it was MVC!)

    =====

    "Your backend might have to deal with a third case: Undefined"

    That's kind of the point of a Radio Button, so you stop the Undefined possibility.

    =====

    "Radiobuttons don't help much if they come alone. "

    The OP said " male and female options ".


    Paul Linton

    Thursday, November 21, 2013 12:28 AM
  • What is the point you are trying to make here?

    Because all I read is "You are wrong, wrong, wrong, wrong". And evaluations do not belong into posts on this Forum. Moreover there is nothing to solve the actuall problem.

    MVC is not a Dispaly Techology, but a Software Design pattern. And you can apply Software design patters to any form of Dispaly Technology (except Console, perhaps).
    And  there is even a MVC Framework for ASP.Net: http://en.wikipedia.org/wiki/ASP.NET_MVC_Framework

    Finally, this part of the View's code looks like ASP.Net for me:

    View
    
    <div class="form-group"> @Html.LabelFor(model => model.Gender, new { @class = "control-label col-md-2" }) 
      <div class="col-md-10"> @Html.EditorFor(model => model.Gender) @Html.ValidationMessageFor(model => model.Gender) 
      </div> 
    </div>

    What Dispaly Technology do you think it is? Because if there is something that looks so much like ASP, I think I need to learn how to differentiate the two.


    Let's talk about MVVM: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b1a8bf14-4acd-4d77-9df8-bdb95b02dbe2 Please mark post as helpfull and answers respectively.

    Thursday, November 21, 2013 11:36 AM
  • I'm trying to make the point that the OP specifically said they are using MVC and that there is a specific forum for ASP.Net MVC questions.  The people in that forum are going to give much better answers than people in this forum.  In particular, the posts made by yourself and others just display a vast lack of knowledge of Microsoft's MVC framework.

    http://www.brainyquote.com/quotes/quotes/m/marktwain103535.html

    A forum like this is precisely the place for evaluations.  If someone asks a questions and someone else gives an incorrect suggestion then it is 100% appropriate to tell the original questioner that they have been given bad/wrong guidance.

    The syntax is obviously Razor - at least it is obvious to anyone who has seen Razor before.


    Paul Linton

    Thursday, November 21, 2013 9:33 PM