Adding Edit ActionResult (3)

Now, we set up the code for handling HttpPost, then store it into database.

Always remembered that everytime we want to store in database, we will use context.

The idea is searching for song inside the database with matched id condition. After that, for one song, repeatedly assign the values with the model values that being inserted in View.

Song song = context.Songs.Where(some => some.Id == model.Id).Single<Song>();
song.Title = model.Title;
song.Singer = model.Singer;
song.Year = model.Year;
song.Writer = model.Writer;
song.GenreId = model.GenreId;
context.SubmitChanges();
return RedirectToAction("Index");

results matching ""

    No results matching ""