I have an entity data model with product types and families. Each product has one family.
I am using this model with an ASP.NET MVC website. I want Family DropDownLists to create and edit views of my product controller.
How to use object navigation properties of an object in DropDownList on my strongly typed ASP.NET MVC Create and edit views?
The following code does not work ...
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 FormCollection? I would rather keep it a strongly typed product.
source share