title: How to capture which radio button is checked when page submit ASP.Net MVC
body: <p>here is my code which display two radio button from my model. the main problem is when i am submitting the form then model sex property is getting null where as i select a radio button before form submit. please help me to find out the problem.</p>
  
  <h2>model class</h2>
  
  <pre><code>public class StudentModel
      {
  
          [Required(ErrorMessage = "First Name Required")] // textboxes will show
          [Display(Name = "First Name :")]
          [StringLength(5, ErrorMessage = "First Name cannot be longer than 5 characters.")]
          public string FirstName { get; set; }
  
          [Required(ErrorMessage = "Last Name Required")] // textboxes will show
          [Display(Name = "Last Name :")]
          [StringLength(5, ErrorMessage = "Last Name cannot be longer than 5 characters.")]
          public string LastName { get; set; }
  
          [Required(ErrorMessage = "Sex Required")]
          [Display(Name = "Sex :")]
          public int SexID { get; set; }
  
          public List&lt;Sex&gt; Sex { get; set; }
  
      }
  
      public class Sex
      {
          public string ID { get; set; }
          public string Type { get; set; }
      }
  </code></pre>
  
  <h2>controller class</h2>
  
  <pre><code>public class HomeController : Controller
      {
          [HttpGet]
          public ActionResult Index()
          {
              ViewBag.Message = "Welcome to ASP.NET MVC!";
              var student = new StudentModel
              {
                  FirstName = "Rion",
                  LastName = "Gomes",
  
                  //I think the best way to populate this list is to call a service here.
                  Sex = new List&lt;Sex&gt;
                  {
                      new Sex{ID="1" , Type = "Male"}, 
                      new Sex{ID="2" , Type = "Female"}
                  }
              };
  
              return View(student );
          }
  
          [HttpPost]
          public ActionResult Index(StudentModel model)
          {
              if (ModelState.IsValid)
              {
                  //TODO: Save your model and redirect 
              }
  
              //Call the same service to initialize your model again (cause we didn't post the list of sexs)
              return View(model);
          }
  }
  </code></pre>
  
  <h2>view code</h2>
  
  <pre><code>@model MvcRadioButton.Models.StudentModel
  
  @Html.BeginForm()
  {
      &lt;div&gt;
          @Html.LabelFor(model =&gt; model.FirstName)
          @Html.EditorFor(model =&gt; model.FirstName)
          @Html.ValidationMessageFor(model =&gt; model.FirstName)
      &lt;/div&gt;
      &lt;div&gt;
          @Html.LabelFor(model =&gt; model.LastName)
          @Html.EditorFor(model =&gt; model.LastName)
          @Html.ValidationMessageFor(model =&gt; model.LastName)
      &lt;/div&gt;
      @{ 
          foreach (var sex in Model.Sex)
          {
              &lt;div&gt;
                  @Html.RadioButtonFor(model =&gt; model.Sex, new { id = "sex" + sex.ID })
                  @Html.Label("sex" + sex.ID, sex.Type)
              &lt;/div&gt;
          }
      }
  
      &lt;input type="submit" value="Submit" /&gt;
  }
  </code></pre>
  
  <p>if possible please run my code and tell me how to achieve my goal and also if anyone think this situation can be handle in better way just change the code then please advise me because i am newbie for MVC.</p>