誰でもこれを行う方法を手伝ってもらえますか?
私はモデルを持っています
Product{ID, Name, SupplierID, Supplier}
Supplier {ID, Name}
を使用して、製品のと の@Html.DropDownListFor
両方に入力したいSupplierID
Supplier
私が使用するProductControllerで
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);
}
( model => model.SupplierID, ViewBag.SupplierId as SelectList) でビューを使用しているdb.SaveChanges
と不平を言いますSupplier
NULL