public ActionResult AddModel() { ModelBrandVM modelbrandVM = new ModelBrandVM() { Brands = db.Brands.ToList() }; return(PartialView("_AddModel", modelbrandVM)); }
public ActionResult AddModel(ModelBrandVM modelbrandVM) { if (ModelState.IsValid == true) { var br = db.Brands.Where(b => b.ID == modelbrandVM.Brandid).FirstOrDefault(); var Model = new Model() { ModelName = modelbrandVM.ModelName, Year = modelbrandVM.Year, Brand = br }; // db.Entry(modelbrandVM).Collection(m=>m.Brands).Load(); db.Models.Add(Model); db.SaveChanges(); } return(RedirectToAction("GetProducts", "VendorProduct")); }