You should not have 3 different properties but instead a single one that will contain the answer. This will allow you to group the radio buttons and be able to select only one of them:
@model AccessEsol.Models.ExamViewModel
@{
ViewBag.Title = "TakeTest";
}
<h2>TakeTest</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<fieldset>
<div class="display-label">
<h3>Click the correct answer:</h3>
</div>
<div class="display-field">
<strong>@Html.DisplayFor(model => model.Text.Text)</strong>
</div>
@Html.DisplayFor(model => model.Foil1.Foil1)
@Html.RadioButtonFor(model => model.Answer, "1")
@Html.DisplayFor(model => model.Foil2.Foil2)
@Html.RadioButtonFor(model => model.Answer, "2")
@Html.DisplayFor(model => model.Foil3.Foil3)
@Html.RadioButtonFor(model => model.Answer, "3")
@Html.DisplayFor(model => model.CorrectAnswer.CorrectAnswer)
@Html.RadioButtonFor(model => model.Answer, "4")
<p>
<input type="submit" value="Submit Answers" />
</p>
</fieldset>
}
and then in your controller action check if the Answer
property value that is sent is the correct one for this question. As you can see from the view we have multiple answer for the question and the value is what will get sent to the server. Usually you will use the ID of the answer as value and on the server you can compare whether this is the correct answer for the question.