I am making a simple survey, for learning basics of ASP.NET MVC 4. Here's my code
[HttpGet]
public ActionResult Index()
{
UserAndTableViewmodel Viewmodel = new UserAndTableViewmodel();
Viewmodel.T = Deserialize();
Viewmodel.U = new User();
for (int i = 0; i < Viewmodel.T.Questions.Count(); i++)
{
Viewmodel.U.UserChoices.Add(new Choice(Viewmodel.T.Questions[i].Choices[0].Value));
}
return View(Viewmodel);
}
[HttpPost]
public ActionResult Index(UserAndTableViewmodel Viewmodel)
{
// Viewmodel.T = Deserialize();
if (ModelState.IsValid)
{
return View("Thanks", Viewmodel);
}
else
{
return View(Viewmodel);
}
}
The XML code is as followed:
<Table>
<Question Content="Question one">
<Choice Value="Answer 1" />
<Choice Value="Answer 2" />
</Question>
<Question Content="Question two">
(...)
</Question>
</Table>
I'm passing deserialised data to "Index" view, where user can choose his answers. Then data is post to [HttpPost] and i want it to render a view, where each question with its answer is written, but problem occurs - Viewmodel.T is equal to null. What am I supposed to do, that I shouldn't deserialize it again?