public ActionResult Create(PrescriptionCreateVM model) { //The problem is that ViewModels is returning the entire object. You must create view models with Fields and Not Objects. Prescription _pres = new Prescription() { PrescriptionDate = model.PrescriptionDate, R_SPH = model.R_SPH, R_CYL = model.R_CYL, R_AXIS = model.R_AXIS, L_SPH = model.L_SPH, L_CYL = model.L_CYL, L_AXIS = model.L_AXIS, CustomerID = model.CustomerID }; if (ModelState.IsValid) { db.Prescriptions.Add(_pres); db.SaveChanges(); return RedirectToAction("Index"); } return View(); }
// GET: /Prescription/Create public ActionResult Create(int CustomerID) { //we need this for the PartialView inside the view. var _customer = db.Customers.Find(CustomerID); PrescriptionCreateVM _viewmodel = new PrescriptionCreateVM { CustomerID = _customer.CustomerID, FullName = _customer.FullName, MobileNumber = _customer.MobileNumber, BirthDate = _customer.BirthDate, RegisterationDate = _customer.RegisterationDate }; //we need to pass a ViewModel becuase it expects in the view. return View(_viewmodel); }