user335160
user335160

Reputation: 1362

Data not saved in database (MVC3)

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");
       }

Upvotes: 2

Views: 485

Answers (2)

Adeel
Adeel

Reputation: 19228

Edit the function signature, as MVC did not binded the function.

EditEventDetails(FormCollection collection)

you can than get the Id from FormCollection object

Upvotes: 1

Jon Skeet
Jon Skeet

Reputation: 1499770

It's not entirely clear what your code is meant to do, but you never use the collection parameter, 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 UpdateModel method do? You're only giving it the information you've just fetched from the repository. I'd expect it to take the FormCollection in its signature, e.g.

UpdateModel(eventsdetails, collection, "tbl_SBAem_Event");

... 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.

Upvotes: 3

Related Questions