Удалить в ASP.NET core3
Deleting operations in the section is difficult
The third party insurance part is removed, but the body insurance part is not removed
And that I want to be returned to the screen Index with the InsuranceController after the removal operation, which doesn't happen
Что я уже пробовал:
// GET:Insurances/Delete/5 public async Task<IActionResult> Delete(int id, int type) { InsuranceViewModel model; if ((InsuranceType)type == InsuranceType.Body) { var bodyInsurance = await _context.BodyInsurance .Include(e => e.InsuranceCompany) .FirstOrDefaultAsync(e => e.Id == id); if (bodyInsurance == null) { return NotFound(); } model = new InsuranceViewModel { ExpireDate = bodyInsurance.ExpireDate, CompanyId = bodyInsurance.InsuranceCompanyId, CompanyName = bodyInsurance.InsuranceCompany.CompanyName, InsuranceType = InsuranceType.Body, IssueDate = bodyInsurance.IssueDate, VehicleInformationId = id }; } else { var thirdParty = await _context.ThirdPartyInsurance .Include(e => e.InsuranceCompany) .FirstOrDefaultAsync(e => e.Id == id); if (thirdParty == null) { return NotFound(); } model = new InsuranceViewModel { ExpireDate = thirdParty.ExpireDate, CompanyId = thirdParty.InsuranceCompanyId, CompanyName = thirdParty.InsuranceCompany.CompanyName, InsuranceType = InsuranceType.Thirdpart, IssueDate = thirdParty.IssueDate, VehicleInformationId = id }; } return View(model); } // POST: Insurances/Delete/5 [HttpPost, ActionName("Delete")] [ValidateAntiForgeryToken] public async Task<IActionResult> DeleteConfirmed(int id, int type) { if ((InsuranceType)type == InsuranceType.Body) { var bodyInsurance = await _context.BodyInsurance.FindAsync(id); if (bodyInsurance == null) { return NotFound(); } _context.BodyInsurance.Remove(bodyInsurance); await _context.SaveChangesAsync(); } else { var thirdParty = await _context.ThirdPartyInsurance.FindAsync(id); if (thirdParty == null) { return NotFound(); } _context.ThirdPartyInsurance.Remove(thirdParty); await _context.SaveChangesAsync(); } return RedirectToAction("VehicleInformations", "Index"); }