I've got an Entity Data Model with Product and Family types. Each Product has one Family.
I'm using this model with an ASP.NET MVC web site. I want Family DropDownLists on the Create and Edit Views of my Product controller.
How Do I Use Entity Object Navigation Properties in a DropDownList on my Strongly Typed ASP.NET MVC Create and Edit Views?
The following code fails...
ProductController:
// POST: /Product/Create
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create(Product p)
{
db.AddToProduct(p);
db.SaveChanges();
return RedirectToAction("Index");
}
Create View:
<p>
<label for="Family">Family:</label>
<%= Html.DropDownList("Family", new SelectList((IEnumerable)ViewData["Families"], "Id", "Name"))%>
<%= Html.ValidationMessage("Family", "*")%>
</p>
Can I do this without using a FormCollection? I would rather keep it a strongly-typed Product.