I have a list of records, for each record I have an edit button to display the data and modify the information. When I clicked the save button the data is not saved in the database. What is the problem with my code, any help please? Here is my code for editing record
[HttpPost,ValidateInput(false)]
public ActionResult EditEventDetails(int id, FormCollection collection)
{
var eventsdetails = _service.GeteventByID(id);
UpdateModel(eventsdetails, "tbl_SBAem_Event");
_eventRepository.SaveChanges();
return RedirectToAction("Index");
}
It’s not entirely clear what your code is meant to do, but you never use the
collectionparameter, which presumably includes the data you want to update. You should presumably be applying that to your model before saving the changes.What does your current
UpdateModelmethod do? You’re only giving it the information you’ve just fetched from the repository. I’d expect it to take theFormCollectionin its signature, e.g.… but I’m really just guessing, as we don’t have much context. Whether that’s the right place or not, it certainly looks like ignoring the incoming data is likely to be the cause.