I have an MVC 5 website - with a controller. If the ModelState.IsValid - then I perform some actions.
If it's invalid I need to tell the user the error (in ViewBag.Message) - and pass the invalid model back to the view so the user can see and edit it.
so this works at the end of the controller action:
return View(MyModelName);
However - why does this also work?:
return View():
Why aren't I required to pass the invalid model back explicitly? Even this doesn't pass a blank model back to the view:
return View(new MyModelName());
I have to execute:
ModelState.Clear();
To get a blank model to the view. Can somebody explain to me why it behaves like this so I can understand what is going on.
I can find nothing on Google about this. Thanks.