public async Task <IActionResult> Edit(int id, [Bind("Id,Title,ReleaseDate,Genre,Price")] Movie movie) { if (id != movie.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(movie); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MovieExists(movie.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(movie)); }
// Bind attribute is a way to protect against over-posting. Only include properties in Bind attribute that you want to change. Although ViewModels is an alternative way to approach overposting. public async Task <IActionResult> Edit(int id, [Bind("ID,Title,RelaseDate,Genre,Price,Rating")] Movie moive) { if (id != moive.ID) { return(NotFound()); } if (ModelState.IsValid) // this method verifies that the data submitted in the form can be used to modit (edit, update) a Movie object. If valid proceeds to run method. { try { _context.Update(moive); await _context.SaveChangesAsync(); // Once method above is verified. This method updates its saved to the database. } catch (DbUpdateConcurrencyException) { if (!MoiveExists(moive.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); // After data has been saved the code redirects theuser to the Index Action mehtod in this controller obviously. Which displays the movie collection including the changes that you have made as a user. } return(View(moive)); }