public ActionResult Edit(Models.Question question, HttpPostedFileBase Image, int[] AnswerID, string[] AnswerContent, string[] IsCorrect) { List <Answer> listAnswer = new List <Answer>(); for (int i = 0; i < AnswerID.Length; i++) { Answer answer = new Answer(); answer.AnswerID = AnswerID[i]; answer.AnswerContent = AnswerContent[i]; answer.IsCorrect = IsCorrect.Contains(AnswerContent[i]); listAnswer.Add(answer); } question.ModifiedBy = int.Parse(Session["Name"].ToString()); if (Image != null && Image.ContentLength > 0) { string filePath = Path.Combine(Server.MapPath("~/Content/QuestionUpload/Images/"), Path.GetFileName(Image.FileName)); Image.SaveAs(filePath); question.Image = Image.FileName; } else { var img = questionService.FindID(question.QuestionID).Image; question.Image = img; } questionService.UpdateQuestion(question); // answerService.DelteAnswerbyQuestionID(question.QuestionID); foreach (var item in listAnswer) { item.QuestionID = question.QuestionID; if (item.QuestionID <= 0) { return(RedirectToAction("Edit", "Question")); } else { answerService.AddAnswer(item); } } return(RedirectToAction("Index")); }