title: Can System.Web.MVC.UpdateModel update EF Navigation Properties?
body: <p>If I have 2 tables in my database: <em>Foo</em> and <em>bar</em>. <strong>Foo</strong> is identified by <em>FooId</em> and <strong>Bar</strong> is identifier by <em>BarId</em>. A <em>Bar</em> can have 0 to many <em>Foos</em> therefore Foo has <em>BarId</em> as a foreign key.</p>
  
  <p>I have a model which represents this and an view which can be used to edit a <em>Foo</em> and select (from a dropdown) the associated <em>Bar</em>.</p>
  
  <p>Given the following method on the controller:</p>
  
  <pre><code>[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");
  }
  </code></pre>
  
  <p>The call to <em>UpdateModel</em> throws an <em>InvalidOperationException</em> with no <em>InnerException</em>:</p>
  
  <pre><code>The model of type 'TestApplication.Models.Foo' was not successfully updated.
  </code></pre>
  
  <p>What's the correct way for my controller to update my Entity Framework-based Model from the drop down in my view?</p>