I’m trying to implement the solution found here, but once I replace my “Users” class with the “EditUserViewModel” class (the one that has less fields than the Users class) and once I get to this line
db.Entry(users).State = EntityState.Modified;
in this code
[HttpPost]
public ActionResult Edit(EditUserViewModel users)
{
if (ModelState.IsValid)
{
db.Entry(users).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
return View(users);
}
I get the error
The entity type EditUserViewModel is not part of the model for the current context.
Now I’m guessing this error is because my DBContext uses the Users class and not the EditUserViewModel class. Am I missing a step or is there any way to fix this?
You need to merge the data from your MV to your Model class.