I'm creating a survey form using ASP.NET MVC architecture.
There is a section where I load the questions for the survey from a model to the view.
The model created as
[NotMapped]
public class QuizForService
{
public int MainDetailsId { get; set; }
public int QuizID { get; set; }
public string Quiz { get; set; }
public string AnswerForQuiz { get; set; }
}
So from the controller, I load the Questions to this model
List < QuizForService > Questionsto = (from q in db.tbl_QuestionsSub
where q.ServiceTypeId == ServiceId select new QuizForService
{
QuizID = q.Id,
Quiz = q.QuestionEng
}).ToList();
Session["Survey"] = Questionsto;
return Json(new { Success = true, questionlist = Questionsto }, JsonRequestBehavior.AllowGet);
So in this view, I load the question from for
loop and the answer list to select users to the related question.
for (int i = 0; i < SurveyList.Count; i++) {
<tr >
<td > @SurveyList[i].Quiz < /td>
<td > @if(@SurveyList[i].QuizID != 8) {
@SurveyList[i].AnswerForQuiz < div class = "radio" >
<input label = "Excellent 😀"
type = "radio"
id = "Excellent"
name = "@SurveyList[i].QuizID"
value = "Excellent"
checked >
<input label = "Good 🙂"
type = "radio"
id = "Good"
name = "@SurveyList[i].QuizID"
value = "Good" >
<input label = "Fair 😐"
type = "radio"
id = "Fair"
name = "@SurveyList[i].QuizID"
value = "Fair" >
<input label = "Poor 😶"
type = "radio"
id = "Poor"
name = "@SurveyList[i].QuizID"
value = "Poor" >
</div> } else { <div class="radio"> <
input label = "Yes 😀"
type = "radio"
id = "Yes"
name = "@SurveyList[i].QuizID"
value = "Yes"
checked >
<input label = "No 😠"
type = "radio"
id = "No"
name = "@SurveyList[i].QuizID"
value = "No" >
<input label = "Maybe 🤔"
type = "radio"
id = "Maybe"
name = "@SurveyList[i].QuizID"
value = "Maybe" >
</div> } </td >
</tr>
}
So the view is a single-page application and the process goes like a wizard.
I thought of submitting get those values using javascript and passing it to the controller using Ajax.
I want to know how to get those question IDs with the customer selected answer to the javascript.