开发者

Show a sequence of views in ASP.NET MVC 2

开发者 https://www.devze.com 2023-02-07 17:47 出处:网络
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.

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 Redir开发者_JS百科ectToAction("LoadNextQuestion", "LoadTest", q);

        }

        return View();                
    }
    else
    {
        return View();
    }
}

public ActionResult LoadNextQuestion(Question objQuestion)
        {
            Question question = questionManager.GetQuestionById(objQuestion.QuestionId);
            ViewData["Question"] = question;
            return View();
        }


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".

0

精彩评论

暂无评论...
验证码 换一张
取 消