// GET: /Administration/Laptops/Create public ActionResult Create() { LaptopCreateViewModel vm = new LaptopCreateViewModel { Manufacturers = db.Manufacturers.All().ToList() }; return View(vm); }
public ActionResult Create(LaptopCreateViewModel postedLaptop, string manufacturer) { if (ModelState.IsValid) { var laptop = postedLaptop.Laptop; laptop.Manufacturer = db.Manufacturers.All().Single(x => x.Name == manufacturer); db.Laptops.Add(laptop); db.SaveChanges(); return RedirectToAction("Index"); } postedLaptop.Manufacturers = db.Manufacturers.All().ToList(); return View(postedLaptop); }