Can anyone help on how to do this please?
I have a model
Product{ID, Name, SupplierID, Supplier}
Supplier {ID, Name}
using a @Html.DropDownListFor
I would like to populate both the SupplierID
and the Supplier
of the product
in the ProductController I use
public ActionResult Edit(Guid id)
{
Product product = db.products.Find(id);
if (product == null)
{
return HttpNotFound();
}
ViewBag.SupplierId = new SelectList(db.Suppliers, "ID", "Name", product.SupplierID );
return View(customer);
}
[HttpPost]
public ActionResult Edit(Customer customer)
{
if (ModelState.IsValid)
{
db.Entry(customer).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
return View(customer);
}
In db.SaveChanges
it complains that Supplier
is NULL
using a view with
(model => model.SupplierID, ViewBag.SupplierId as SelectList)