//edit question public ActionResult EditQuestion(string Id, string Content, int?Count, string[] editdynamicField) { QuestionViewModel questionViewModel = new QuestionViewModel(db.Questions.Find(new Guid(Id))); if (questionViewModel != null) { questionViewModel.Content = Content; if (questionViewModel.Type == "Checkbox") { QuestionAnswerViewModel answer; var answers = db.QuestionAnswers.Where(x => x.QuestionId == questionViewModel.Id); int i = 0; foreach (var item in answers) { answer = new QuestionAnswerViewModel(item); if (editdynamicField.Count() > i) { answer.Answer = editdynamicField[i]; answer.UpdateQuestionAnswer(answer); } else { answer.DeleteQuestionAnswer(answer); } i++; } if (answers.Count() < editdynamicField.Count()) { for (int j = i; j < editdynamicField.Count(); j++) { answer = new QuestionAnswerViewModel { Id = Guid.NewGuid(), QuestionId = questionViewModel.Id, Answer = editdynamicField[j] }; answer.AddQuestionAnswer(answer); } } } questionViewModel.UpdateQuestion(questionViewModel); } return(RedirectToAction("Create", "Surveys")); }