title: DropDownListFor & Navigation Properties
body: <p>I'm running into an issue trying to use @Html.DropDownListFor().</p>
  
  <p>I have a model with a navigation property on it:</p>
  
  <pre><code>public class Thing {
    ...
    public virtual Vendor Vendor { get; set; }
  }
  </code></pre>
  
  <p>In the controller I'm grabbing the vendor list to throw into the ViewBag:</p>
  
  <pre><code>public ActionResult Create() {
    ViewBag.Vendors = Vendor.GetVendors(SessionHelper.CurrentUser.Unit_Id);
    return View();
  }
  </code></pre>
  
  <p>The html item in the view looks like this:</p>
  
  <pre><code>@Html.DropDownListFor(model =&gt; model.Vendor, new SelectList(ViewBag.Vendors, "Id", "Name"), "---- Select vendor ----")
  @Html.ValidationMessageFor(model =&gt; model.Vendor)
  </code></pre>
  
  <p>The dropdown list is being rendered, and everything seems fine until I submit the form. The HttpPost Create method is returning false on the ModelState.IsValid and throwing a Model Error: <em>The parameter conversion from type 'System.String' to type '...Models.Vendor' failed because no type converter can convert between these types.</em></p>
  
  <p>If I let the page post through, I end up with a server error:
  <em>Exception Details: System.ArgumentNullException: Value cannot be null.
  Parameter name: items</em></p>
  
  <p>After searching high and low I haven't been able to find a reason that the @Html.DropDownListFor() isn't properly auto-binding a Vendor object to the navigation property.</p>
  
  <p>Any help would be greatly appreciated.</p>
  
  <p>EDIT:
  I ended up having to explicitly set the ForeignKey attributes so that I could directly access "Vendor_Id" then I changed the DropDownListFor to point to "Vendor_Id" instead of the navigation property. That seems to work.</p>