如果我在数据库中有2个表格:Foo和bar。 <<>Foo通过FooId和Bar通过<>BarId识别。
我的模型体现了这一点,一种看法可用于选择相关的
鉴于控制器有以下方法:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(int id, FormCollection formCollection)
{
Foo originalFoo = FooById(id);
if (!ModelState.IsValid)
{
return View(new VenueViewModel(originalVenue, _db.GetCounties(), _db.VenueTypeSet));
}
UpdateModel(originalFoo);
/* Instead of using UpdateModel I could just iterate through
formCollection and manually update originalFoo, it would
work but surely there is a better way? */
_db.SaveChanges();
return RedirectToAction("Index");
}
电话UpdateModel向InvalidOperationException<>>
The model of type TestApplication.Models.Foo was not successfully updated.
我认为,我的控制者从下降中更新基于实体框架的模式,有什么正确方法?