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.
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
}
Unsure of another way to do this like
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult GradeTest(int? testID, string[] questionIDs, string[] answerIDs)
What i'm doing feels a little hacky. Please help OR let me know i'm on the right track. Thanks!