How ASP.NET MVC passes model to the view without explicitly passing it
Posted
by
Vlad Bezden
on Stack Overflow
See other posts from Stack Overflow
or by Vlad Bezden
Published on 2012-11-04T16:58:47Z
Indexed on
2012/11/04
16:59 UTC
Read the original article
Hit count: 337
asp.net-mvc
|aps.net
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
© Stack Overflow or respective owner