Is there any way to have a strongly typed UpdateModel(myEntity, MagicStringPrefix)
without the magic string?
So I have a view model looking like
public class FooViewModel {
public Foo Foo { get; set; }
...
}
And in my controller I have
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(int id, FormCollection collection)
{
var foo = _fooRepo.GetFoo(id);
try
{
UpdateModel(foo, "Foo");
_fooRepo.Save();
return RedirectToAction("Index");
}
catch (Exception ex)
{
return View(new FooViewModel(foo));
}
}
I would like to do this without having to use magic strings. Something like UpdateModel(foo, Model.Foo)
would be fine. However, I prefer to simply have UpdateModel(foo)
and have it infer the prefix given Foo is the class name, but I really don't want to have to write my own ModelBinder.