I started using MVC recently and I'm getting little disappointed. Instead of helping me, the framework is getting in my way.
I'm trying to write a controller action like this (pseudo code)
ActionResult Save(long id, string whichForm)
{
if (whichForm == "A")
{
var vm = CreateModel(Request.Form);
if (!TryValidate(vm))
return View(vm);
else
return RedirectToRoute("Success");
}
else ....
}
Basically I'd like to have control over when my view-model is constructed and when it is validated. Is this possible? How can I implement CreateModel method? Consider I may want to create several different view-models within this controller action.
*Rant: I don't really understand why view-model binding and validation are mixed together in DefaultModelBinder. Seems like code smell. Specially when it's hard to override this behaviour.