I would really appreciate some insight on this: The following code
[HttpPost]
public ActionResult Edit(BeamCollection beamcollection)
{
if (ModelState.IsValid)
{
beamcollection.BeamMaterial = db.Types.Find(Convert.ToInt32(Request.Form.Get("BeamMaterial_ID")));
db.Entry(beamcollection).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Details", "Bridge");
}
return View(beamcollection);
}
When I attempt to modify a BeamCollection record, all changes are reflected and saved to the DB except for the beamcollection.BeamMaterial which takes the selected value from a DropDownList. When I debug, I can see that the selected value is being assigned to beamcollection.BeamMaterial!
By the way, this field is defined as follows
public virtual AllTypes BeamMaterial { get; set; }
So it reflects a one to many relationship with AllTypes, but it is a unidirectional relationship.
What is kind of strange (to me), is the the same technique is used for the Create action and it perfectly works:
public ActionResult Create(BeamCollection beamcollection)
{
if (ModelState.IsValid)
{
beamcollection.BridgeInfo = db.Bridges.Find(bridgeID);
beamcollection.BeamMaterial = db.Types.Find(Convert.ToInt32(Request.Form.Get("BeamMaterial_ID")));
db.BeamCollections.Add(beamcollection);
db.SaveChanges();
return RedirectToAction("Details", "Bridge");
}
return View(beamcollection);
}
Why is this happening and how to make it work, Please help.