This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Feb 24th, 2012  |  syntax: C#  |  size: 0.34 KB  |  views: 20  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public ActionResult Create(Question question)
  2. {
  3.     if (ModelState.IsValid)
  4.     {
  5.         question.Answers = new List<Answer>();
  6.         question.Answers.Add(new Answer { AnswerText = "MyAnswer" });
  7.         db.Questions.Add(question);
  8.         db.SaveChanges();
  9.         return RedirectToAction("Index");  
  10.     }
  11.     return View(question);
  12. }
clone this paste RAW Paste Data