title: ASP.NET MVC Best way to handle dynamic number of parameters in controller
body: <p>I have a view model for exams. Each exam has an arbitrary number of questions. It could be 1 question or it could be 50 questions. After this gets submitted i need to loop thru the questions and check the answers. I have a solution but i feel like it's not a best practice.</p>
  
  <pre><code>int questionNumber = 1;
  
          while (Request.Form["Question" + questionNumber.ToString()] != null)
          {
              int questionID = Convert.ToInt32(Request.Form["Question" + questionNumber.ToString()]);
              int answerID = Convert.ToInt32(Request.Form["Answer" + questionNumber.ToString()]);
  
              //TODO: Check if answer is correct
          }
  </code></pre>
  
  <p>Unsure of another way to do this like</p>
  
  <pre><code>    [HttpPost]
      [ValidateAntiForgeryToken]
      public ActionResult GradeTest(int? testID, string[] questionIDs, string[] answerIDs)
  </code></pre>
  
  <p>What i'm doing feels a little hacky. Please help OR let me know i'm on the right track. Thanks!</p>