where to store temporary data in MVC 2.0 project
Posted
by StuffHappens
on Stack Overflow
See other posts from Stack Overflow
or by StuffHappens
Published on 2010-05-05T18:44:13Z
Indexed on
2010/05/05
18:58 UTC
Read the original article
Hit count: 173
Hello!
I'm starting to learn MVC 2.0 and I'm trying to create a site with a quiz: user is asked a question and given several options of answer. If he chooses the right answer he gets some points, if he doesn't, he looses them.
I tried to do this the following way
public class HomeController : Controller
{
private ITaskGenerator taskGenerator = new TaskGenerator();
private string correctAnswer;
public ActionResult Index()
{
var task = taskGenerator .GenerateTask();
ViewData["Task"] = task.Task;
ViewData["Options"] = task.Options;
correctAnswer= task.CorrectAnswer;
return View();
}
public ActionResult Answer(string id)
{
if (id == correctAnswer)
return View("Correct")
return View("Incorrect");
}
}
But I have a problem: when user answers the cotroller class is recreated and I loose correct answer. So what is the best place to store correct answer? Should I create a static class for this purpose?
Thanks for your help!
© Stack Overflow or respective owner