コード例 #1
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var student = await _context.Students.FindAsync(id);

            if (student == null)
            {
                return(NotFound());
            }

            try
            {
                _context.Students.Remove(student);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            catch (DbUpdateException /* ex */)
            {
                //Log the error (uncomment ex variable name and write a log.)
                return(RedirectToAction("./Delete",
                                        new { id, saveChangesError = true }));
            }
        }
コード例 #2
0
 public async Task <IActionResult> OnPostAsync(int id)
 {
     try
     {
         if (await _context.Departments.AnyAsync(
                 m => m.DepartmentID == id))
         {
             // Department.rowVersion value is from when the entity
             // was fetched. If it doesn't match the DB, a
             // DbUpdateConcurrencyException exception is thrown.
             _context.Departments.Remove(Department);
             await _context.SaveChangesAsync();
         }
         return(RedirectToPage("./Index"));
     }
     catch (DbUpdateConcurrencyException)
     {
         return(RedirectToPage("./Delete",
                               new { concurrencyError = true, id = id }));
     }
 }