选择的答案是变量保持选项是和否,因此当用户选择时 没有单选按钮它必须退出并加载另一页
[HttpPost]
public ActionResult Index(Evaluation answer)
{
using (QuestionMangerDBDataContext data = new QuestionMangerDBDataContext())
{
if (ModelState.IsValid)
{
var selectedAnswer = answer.selectedAnwser;
var qId = answer.questionId;
// Save the data
QuestionMangerDATA.questionManagerAnswer tmpQAA = new QuestionMangerDATA.questionManagerAnswer();
tmpQAA.QuestionID = qId;
tmpQAA.QuestionAnswerID = int.Parse(selectedAnswer);
tmpQAA.UserId = 4;
tmpQAA.AnswerValue = "WHAT IS THIS?!";
if (selectedAnswer == "NO")
{
tmpQAA.QuestionID = qId;
}
data.questionManagerAnswers.InsertOnSubmit(tmpQAA);
data.SubmitChanges();
}
答案 0 :(得分:1)
嗯,奇怪的样本,因为你的ActionResult
...现在没有返回任何内容。
您可以使用if else进行重定向,例如,可以表示为
return selectedAnswer == "NO"
? RedirectToAction("someAction")
: RedirectToAction("someOtherAction")
或如果您不希望执行selectedAnswer == "NO"
if (selectedAnswer=="No")
return RedirectToAction("someAction");
//this part won't be executed if selectedanswer == "No"
data.questionManagerAnswers.InsertOnSubmit(tmpQAA);
data.SubmitChanges();
return RedirectToAction("someOtherAction");