public async Task <IActionResult> Edit(int id, [Bind("BookId,Title,Description,PublishedOn,AuthorId")] Book book) { if (id != book.BookId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(book); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BookExists(book.BookId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["AuthorId"] = new SelectList(_context.Set <Author>(), "AuthorId", "Name", book.AuthorId); return(View(book)); }
public async Task <IActionResult> Edit(int id, [Bind("AuthorId,Name")] Author author) { if (id != author.AuthorId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(author); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AuthorExists(author.AuthorId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(author)); }