I'm creating a simple survey using ASP.NET MVC. The administrator will create questions answerable by 3 options only - Strongly agree, somewhat agree, strongly disagree) via the Create View.
The user will then have to select their answer using radiobutton.
- How should I add it in my view?
Currently, this is how my view looks like (I know this is still wrong as im still trying to understand how to do this correctly):
<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, "Strongly Agree", new { QuestionID = item.QuestionID })
</td>
<td align="center">
@Html.RadioButtonFor(modelItem => item.Answer, "Somewhat Agree", new { QuestionID = item.QuestionID })
</td>
<td align="center">
@Html.RadioButtonFor(modelItem => item.Answer, "Strongly Disagree", new { QuestionID = item.QuestionID })
</td>
</tr>
}
</table>
- How would I get the selected answer of the user for each question and save it to my database?
My tables are as follows:
tblTestProper: [QuestionID
, UserID
, Answer
]
tblQuestions: [QuestionID
, Question
]
Are there any examples or ideas I can follow to achieve this? Thanks for any help.