title: MVC 4 getting values of selected radio buttons
body: <p>I'm just venturing out into the world of MVC (v4) and I'm having real trouble getting the actual selected values of a list of radiobutton lists. I'm pulling the data from an Umbraco database (but I guess the principle of what I'm trying to do will be the same) where there are list of questions with each question having a list of answers. I'll post everything that I've done so far in the hope that someone more intelligent than I could point me in the right direction:</p>
  
  <p>Here's my content structure</p>
  
  <p><img src="https://i.stack.imgur.com/Z8Lbf.jpg" alt="enter image description here"></p>
  
  <p>My Model </p>
  
  <pre><code>namespace ICASolution.Models
  {
      public class MultipleChoiceViewModel
      {
          public int iQuestionID { get; set; }
          public string zQuestionTitle { get; set; }
          public string zQuestionText { get; set; }
          public List&lt;Answers&gt; lAnswers { get; set; }
  
      }
  
      public class Answers
      {
          public int iAnswerID { get; set; }
          public string zAnswerText { get; set; }
          public bool bCorrect { get; set; }
          public string selectedAnswer { get; set; }
      }
  }
  </code></pre>
  
  <p>My surface controller:</p>
  
  <pre><code>namespace ICASolution.Controllers
  {
      public class MultipleChoiceSurfaceController : SurfaceController
      {
          //
          // GET: /MultipleChoiceSurface/
  
          //public ActionResult Index()
          //{
          //    return PartialView("MultipleChoice", new MultipleChoiceViewModel());
          //}
          [HttpPost]
          public ActionResult Grade(MultipleChoiceViewModel model)
          {
  
              return RedirectToCurrentUmbracoPage();
          }
  
          public ActionResult Index()
          {
              var TestPage = Umbraco.Content(CurrentPage.Id);
              var questions = new List&lt;MultipleChoiceViewModel&gt;();
  
              foreach (var child in TestPage.Children)
              {
                  var questionid = child.Id;
                  var questiontitle = child.GetPropertyValue("questionTitle");
                  var questiontext = child.GetPropertyValue("questionText");
  
                  questions.Add(new MultipleChoiceViewModel { iQuestionID = questionid, zQuestionTitle = questiontitle, zQuestionText = questiontext, lAnswers = answerList(questionid) });
  
              }
  
              return PartialView("MultipleChoice", questions);
          }
  
          public List&lt;Answers&gt; answerList(int iMyQuestionID)
          {
              var questionPage = Umbraco.Content(iMyQuestionID);
              var answers = new List&lt;Answers&gt;();
  
  
              foreach(var child in questionPage.Children)
              {
                  answers.Add(new Answers { iAnswerID = child.Id, zAnswerText = child.GetPropertyValue("answerTitle"), bCorrect =  child.GetPropertyValue("correctAnswer") });
              }
  
              return answers;
          }
  
      }
  }
  </code></pre>
  
  <p>and finally my partial:</p>
  
  <pre><code>@model IEnumerable&lt;ICASolution.Models.MultipleChoiceViewModel&gt;
  
  
  &lt;div class="ethicsTestContainer"&gt;
      &lt;div class="col-md-12"&gt;
          &lt;div class="col-md-12 noRPadding"&gt;
              @using (Html.BeginUmbracoForm&lt;ICASolution.Controllers.MultipleChoiceSurfaceController&gt;("Grade")) { 
  
                      foreach (var item in Model)
                      {
                          &lt;div class="form-group"&gt;
                              &lt;p&gt;&lt;strong&gt;@item.zQuestionTitle&lt;/strong&gt;&lt;/p&gt;
                              &lt;p&gt;@item.zQuestionText&lt;/p&gt;
  
                              @{
                                  foreach (var answerItem in item.lAnswers)
                                  {
                                      &lt;div class="radio radio-danger"&gt;
                                          @Html.RadioButton(answerItem.iAnswerID.ToString(), answerItem.iAnswerID, new { @type = "radio", @id = answerItem.iAnswerID, @name = item.iQuestionID })
  
                                          @*&lt;input type="radio" name="@item.iQuestionID" id="@answerItem.iAnswerID" value="option1"&gt;*@
                                          &lt;label for="@answerItem.iAnswerID"&gt;
                                              @answerItem.zAnswerText &lt;span&gt;&amp;nbsp;&lt;/span&gt;@answerItem.bCorrect
                                          &lt;/label&gt;
                                      &lt;/div&gt;
                                  }
                              }
                          &lt;/div&gt;
                      }
  
  
                  &lt;div class="col-sm-8 col-sm-push-2"&gt;
                      &lt;button type="submit" class="btn btn-default btn-block"&gt;CLICK HERE TO COMPLETE YOUR ETHICS TEST&lt;/button&gt;
                  &lt;/div&gt;
  
              }
  
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Everything renders fine when displayed to the user:</p>
  
  <p><img src="https://i.stack.imgur.com/1AUJe.jpg" alt="enter image description here"></p>
  
  <p>But I just can't work out how to get the selections that the user has made on the HTTPPOST (basically I need to count the amount of correct answers that they have made).</p>