private static List<AnswerModel> PopulateAnswers(SqlDataReader reader) { var answerList = new List<AnswerModel>(); while (reader.Read()) { var answerModel = new AnswerModel { Id = int.Parse(reader["id"].ToString()), answer = reader["answer"].ToString(), QuestionId = int.Parse(reader["question_id"].ToString()) }; answerList.Add(answerModel); } return answerList; }
public ActionResult Create(AnswerModel collection) { try { // TODO: Add insert logic here if (ModelState.IsValid && Request["question_id"] != null) { collection.QuestionId = int.Parse(Request["question_id"]); collection.Save(); return RedirectToAction("Index", "question"); } else { return View(); } } catch { return View(); } }