在 ASP.NET MVC 2 中显示一系列视图
我收集了一系列问题作为列表。对于每个问题,我想显示单独的视图,一个用户给出答案,下一个问题将呈现,下一个问题将再次呈现。
我可以这样做吗?
[HttpGet]
public ActionResult Index(int? testId)
{
int id = Convert.ToInt32(testId);
List<Question> questionList;// = new List<Question>();
questionList = questionManager.GetquestionsByTestId(id);
if (questionList != null)
{
foreach (Question q in questionList)
{
return RedirectToAction("LoadNextQuestion", "LoadTest", q);
}
return View();
}
else
{
return View();
}
}
public ActionResult LoadNextQuestion(Question objQuestion)
{
Question question = questionManager.GetQuestionById(objQuestion.QuestionId);
ViewData["Question"] = question;
return View();
}
I have collection of Questions as List. For each question I want to show separate view, one user give answer, next question will render, again next will render.
Can i do this ?
[HttpGet]
public ActionResult Index(int? testId)
{
int id = Convert.ToInt32(testId);
List<Question> questionList;// = new List<Question>();
questionList = questionManager.GetquestionsByTestId(id);
if (questionList != null)
{
foreach (Question q in questionList)
{
return RedirectToAction("LoadNextQuestion", "LoadTest", q);
}
return View();
}
else
{
return View();
}
}
public ActionResult LoadNextQuestion(Question objQuestion)
{
Question question = questionManager.GetQuestionById(objQuestion.QuestionId);
ViewData["Question"] = question;
return View();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是行不通的,因为您将通过 return 终止循环。
快速思考一下:将要调用的操作列表存储在页面“主框架”上的 JavaScript 数组中,并使用 jQuery 的 ajax 加载方法来调用要呈现的操作并将响应放在“主框架”中框架”。
This will not work, as you will terminate the loop with the return.
Quick thought about this: Store a list of actions you want to call in a JavaScript array on a "main frame" of your page and use jQuery's ajax load method, to call the actions you want to render and place the response in your "main frame".