// GET: Class2/Create public ActionResult Create() { Class2VM vm = new Class2VM(); vm.Class1s = db.Class1.ToList(); return(View(vm)); }
public ActionResult Create(Class2VM vm) { if (ModelState.IsValid) { vm.Class2.Class1 = db.Class1.Find(vm.Class1Id); db.Class2.Add(vm.Class2); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(vm)); }