public async Task <IActionResult> OnPostAsync(int?id, bool?saveChangesError = false) { if (id == null) { return(NotFound()); } if (saveChangesError.GetValueOrDefault()) { ErrorMessage = "Delete failed. Try again"; } Trucks = await _context.Trucks.FindAsync(id); if (Trucks == null) { return(NotFound()); } try { _context.Trucks.Remove(Trucks); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } catch (Exception) { return(RedirectToAction("./Delete", new { id, saveChangesError = true })); } }
// To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(Trucks).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TrucksExists(Trucks.ID)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }