I am new to MVC. I am adding into the database OK with this code:
[HttpPost]
[Authorize]
public ActionResult Add(CourseModel course)
{
course.UserID = (Guid)Membership.GetUser().ProviderUserKey;
_db.Class.Add(course);
_db.SaveChanges();
return View();
}
But how do I correctly update a ‘course’ if I already have it in the DB, but the user updated one field?.
I can delete it, and then read the updated one and that works OK but I’m pretty sure that is not the correct way of doing it.
Thank you.
Assuming you’re using EF, to update a record in database. Using the following code