How ASP.NET MVC passes model to the view without explicitly passing it
- by Vlad Bezden
Here is one of the examples that I've seen on how to do validation on Controller:
[HttpPost]
public ViewResult Create(MyModel response)
{
if (ModelState.IsValid)
{
return View("Thanks");
}
else
{
return View();
}
}
If there are validation errors, than return View() method is called without any parameters. Obviesly you have @Html.ValidationSummary() in your View and Model has all required properties attributes.
The data that was entered into the form was preserved and displayed again when the view was rendered with the validation summary.
My question is how data preserved? Since it was not passed to the View like
return View(response);
Thanks a lot.
Sincerely,
Vlad