I'm creating a simple survey using ASP.NET MVC wherein the questions are answerable by 3 options - Strongly agree, somewhat agree, strongly disagree. The user have to select his answer by selecting a radiobutton.
Right now, I can only select one radiobutton for the whole table. I wish to select a RadioButton for each row in the table, for a user to select his answer for every corresponding question.
This is my ViewModel:
public class PsychTestViewModel
{
//PsychTestQuestion
public int QuestionID { get; set; }
public string Question { get; set; }
//PsychTest
public string UserID { get; set; }
public int Answer { get; set; }
}
My View:
<table class="table">
<tr>
<th>
Question
</th>
<th class="text-center">
Strongly Agree
</th>
<th class="text-center">
Somewhat Agree
</th>
<th class="text-center">
Strongly Disagree
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Question)
</td>
<td align="center">
@Html.RadioButtonFor(modelItem => item.Answer, "1")
</td>
<td align="center">
@Html.RadioButtonFor(modelItem => item.Answer, "2")
</td>
<td align="center">
@Html.RadioButtonFor(modelItem => item.Answer, "3")
</td>
</tr>
}
</table>
How can I group these RadioButtons so that the user can select one radiobutton for every row?