I have a survey form with the following data hierarchy
survey - surveyQuestions - surveyQuestionOptions
I use updateModel to update the Survey object in my save method, which is great for polling and pollingQuestions, however surveyQuestionOptions appear updated when I check the updateSurvey variable in the debugger, but after I call SubmitChanges, I get new surveyQuestionOption entries instead of updates. My code is as follows
HTML
<%= Html.TextBox("Survey.Id", Model.Id)%> <%= Html.TextBox("Survey.SurveyName", Model. SurveyName)%> <%= Html.TextBox("Survey.SurveyQuestions[0].Id", Model.Id)%> <%= Html.TextBox("Survey.SurveyQuestions[0].Question", Model. Question)%> <%= Html.TextBox("Survey.SurveyQuestions[0].SurveyQuestionOptions[0].Id", Model.Id)%> <%= Html.TextBox("Survey.SurveyQuestions[0].SurveyQuestionOptions[0].Option", Model. Option)%>
controller
[AcceptVerbs(HttpVerbs.Post)] public ActionResult Save(int? id, IList<ChannelForm> channelForms, FormCollection fc) { Survey updateSurvey = new Survey(); //if this is an existing Surveyretrieve that record from the database ready for updating if (id != 0) { updateSurvey = surveynRepository.GetSingle(Convert.ToInt32(id)); } try { // updateSurvey and all child elements UpdateModel(updateSurvey, "Survey"); surveyRepository.Save(); return View(); }catch {return View();} }
Any help is appreciated
Joe source share