我是ASP MVC的新手,在使用submit form \ Ajax实现局部视图时遇到了问题。
我的部分观点:
@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">
我的问题模型:
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;}
}
在存储库中定义了20个问题。
我的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.
}
最后是MyAnswerModel:
public string UserName {get;set;}
public string Email {get;set;}
public List<char>answers {get;set;}
我认为需要遵循以下算法: