I have an Edit scaffold that isn't properly changing a field of mine..
Here's the model for the class I'm trying to edit:
namespace SmartLivingAdvisor.Models
{
public class SubCategoryClass
{
public int ID { get; set; }
public string Name { get; set; }
public int? CategoryID { get; set; }
public virtual CategoryClass CatergoryClass { get; set; }
}
}
My edit form is not properly reassgning a new CatergoryClass!
Here's the post Edit function:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit([Bind(Include = "ID,Name,CategoryID")] SubCategoryClass subCategoryClass)
{
if (ModelState.IsValid)
{
subCategoryClass.CatergoryClass = db.CategoryClasses.Find(subCategoryClass.CategoryID);
db.Entry(subCategoryClass).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
return View(subCategoryClass);
}
This line:
subCategoryClass.CatergoryClass = db.CategoryClasses.Find(subCategoryClass.CategoryID);
Is not doing what it should do. It should assign the new CatergoryClass.
Aucun commentaire:
Enregistrer un commentaire