I have an quiz application which has questions with multiple answers. The problem is that I don't have an idea how to send the answered options to the controller to check if they are correct? So far, I have made a form with multiple check boxes but I am confused which type should the controllers method receive?
Here is the form:
@using (Html.BeginForm("CheckAnswers", "Questions", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
@foreach (var item in Model.OfferedAnswers)
{
<hr />
<div class="form-group">
@Html.HiddenFor(modelItem => item.ID)
@Html.HiddenFor(modelItem=>item.QuestionID)
@Html.HiddenFor(modelItem=>item.AnswerID)
@Html.LabelFor(modelItem => item.Answer.text, "AnswerID", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.CheckBox("IsCorrect", false, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(modelItem => item.Answer.text, "", new { @class = "text-danger" })
</div>
</div>
}
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Провери" class="btn btn-default" />
</div>
</div>
</div>
}
Here is the code of the controller method:
public ActionResult CheckAnswers(int ID, int QuestionID, int AnswerID, bool isCorrect)
{
OfferedAswer oa = db.OfferedAnswers.Find(ID);
return RedirectToAction("Index");
}
This may work for single choice answers. I am new to .net mvc . Thanks in advance.