On loading up a form, I retrieve a list of items to put in a combo-box. Now lets say during the post, there is an error. I have to re-write the code to get and build back my viewmodel again?
For eg.
public ActionResult Index()
{
var vModel = GetViewModel();
return View(vModel);
}
[HttpPost]
public ActionResult Index(SomeModel model)
{
if (ModelState.IsValid)
{
}
else
{
//Why do I have to write monkey-code here?
var vModel = GetViewModel();
return View(vModel);
}
}
Am I going to have to do it like this example where I have a method to build my viewmodel for both actions?
Why not just
return Index();instead?