View:
- @model IEnumerable
- @foreach(var item in Model)
- {
-
- @item.category
- "DeleteCategory" asp-route-id="@item.Id">Delete
- }
Controller:
- public async Task
DeleteCategory( int Id) - {
- if (Id == null)
- {
- return NotFound();
- }
- var findId = _context.Categorys.FirstOrDefault(x => x.Id == Id);
- _context.Categorys.Remove(findId);
- _context.SaveChangesAsync();
- return RedirectToAction(nameof(Category));
- }
I have to press several times on the Delete link in order for it to work
when it doesnt work i get the error:
Microsoft.EntityFrameworkCore.Database.Transaction: Error: An error occurred using a transaction.
I would like to Understand why the code is not running smoothly
Thanks
Satya KarkiPosted Apr 15, 2021, 2:17 PM
Rijwan AnsariPosted Apr 15, 2021, 2:11 PM
Satya KarkiPosted Apr 15, 2021, 2:07 PM