title: ASP.NET MVC model binding foreign key relationship
body: <p>Is it possible to bind a foreign key relationship on my model to a form input?</p>
  
  <p>Say I have a one-to-many relationship between <code>Car</code> and <code>Manufacturer</code>. I want to have a form for updating <code>Car</code> that includes a select input for setting <code>Manufacturer</code>. I was hoping to be able to do this using the built-in model binding, but I'm starting to think I'll have to do it myself.</p>
  
  <p>My action method signature looks like this:</p>
  
  <pre><code>public JsonResult Save(int id, [Bind(Include="Name, Description, Manufacturer")]Car car)
  </code></pre>
  
  <p>The form posts the values Name, Description and Manufacturer, where Manufacturer is a primary key of type <code>int</code>. Name and Description get set properly, but not Manufacturer, which makes sense since the model binder has no idea what the PK field is. Does that mean I would have to write a custom <code>IModelBinder</code> that it aware of this? I'm not sure how that would work since my data access repositories are loaded through an IoC container on each <code>Controller</code> constructor.</p>