These are my model classes.
public class Survey
{
[Key]
public int SurveyID { get; set; }
[Required]
public string Title { get; set; }
[DataType(DataType.Text)]
[Required]
public string Description { get; set; }
public virtual Category Category { get; set; }
}
public class Category
{
[Key]
public int CategoryID { get; set; }
public string CategoryText { get; set; }
}
In the edit action of the SurveyController the survey properties are updating but not the category.
Here is the edit action code.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(Survey survey)
{
db.Database.Log = s => Debug.WriteLine(s);
if (ModelState.IsValid)
{
db.Entry(survey).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
return View(survey);
}