How to Edit and Save ViewModels data back to database

后端 未结 3 1228
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-05 23:40

I have a ViewModel which is joined by three Entities to get data from all entities into one view form. Although i succeeded to implement the same. But i have no idea how to Edit

3条回答
  •  情话喂你
    2021-02-06 00:17

    Here, for creating:

    [HttpPost]
    public ActionResult Create(DoctorViewModel model)
    {
        if (ModelState.IsValid)
        {
            model.Doctor.DoctorAddress = model.DoctorAddress;
            model.Doctor.DoctorCharge = model.DoctorCharge;
            db.Doctors.Add(doctor);
            db.SaveChanges();
            return RedirectToAction("Index");
        }
    
        return View(doctor);
    }
    

提交回复
热议问题