I am pretty new to ASP MVC and faced problem while implementing the partial view with submit form\Ajax.
My Partial View :
@model IList<QuestionModel>
<label>@model.Question</label>
<form action="/ResponseGather/GetAnswers" method="POST"> //Question#1
<input type="radio" name="answer" value="A"/> @model.AnswerOptionA
<input type="radio" name="answer" value="B"> @model.AnswerOptionB
<input type="submit">
My Question Model :
public class Question{
public int Id {get;set;}
public int NumberInSystem {get;set;}
public string Question {get;set;}
public string AnswerOptionA {get;set;}
public string AnswerOptionB {get;set;}
}
In the repository there are defined 20 questions.
My ResponseGatherController:
public class ResonseGatherController : Controller {
public void GetAnswers(AnswerModel model){
//WHAT to do here?
//I need gather answers to all 20 questions and then send it to DB.
}
And finally MyAnswerModel:
public string UserName {get;set;}
public string Email {get;set;}
public List<char>answers {get;set;}
I think that need following algorithm :
- Send to Partial View Question#1
- Wait User to Submit
- By using Ajax/Json/Whatever is used in this situation send next question to the partial without reloading the page.
- Save Question#1 answer somewhere and the same for all 20 questions.
- Only when all 20 questions answered, then send AnswerModel to DB by EF.
- ...Logic to analyze AnswerModel...
Could you advice me what to do? Should I use Json here? Or should I send an array of questions to the method?