Link to home
Start Free TrialLog in
Avatar of Member_2_1242703
Member_2_1242703

asked on

Updating specific fields only in MVC/Entity controller

I'm currently using this action to edit a record in my database table:

  public ActionResult Edit([Bind(Include = "ID,StartDate,EndDate,Type,Hours,Comments")] PTO_REQUEST pTO_REQUEST)
        {
            if (ModelState.IsValid)
            {
                db.Entry(pTO_REQUEST).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Create");
            }
            return View(pTO_REQUEST);
        }

Open in new window


It updates the fields I want, but it sets everything else to NULL. How do I get it to just update the fields I want and not anything else?
ASKER CERTIFIED SOLUTION
Avatar of vr6r
vr6r

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Member_2_1242703
Member_2_1242703

ASKER

Thank you, it does help a lot. Nicely explained. Thanks again!