Hope someone can help me with this.
I have a controller in my ASP.NET MVC project that is used for editing a so called survey form. The survey form has a 1-to-1 relation with objects of type Form. When saving the survey form I also want to set the name of the form. However the form property is null. The FormID property has the correct value (using database first, EF5). Here is the problem.
[HttpPost]
public ActionResult Edit(SurveyForm surveyform)
{
if (ModelState.IsValid)
{
db.Entry(surveyform).State = EntityState.Modified;
// This cannot be done because surveyform.Form is null
surveyform.Form.Name = "Wish this would work!";
db.SaveChanges();
}
}
My question is: how can I 'attach' surveyform to the model so that is loads related data?
Thanks in advance!
SurveyFormas a parameter to Edit method? Are you POSTing it?