View:
- @model IEnumerable<Webshop.Models.Categorys>
-
- <ul>
- @foreach(var item in Model)
- {
- <li>@item.category
- <a asp-action="DeleteCategory" asp-route-id="@item.Id">Delete</a></li>
- }
- </ul>
Controller:
- public async Task<IActionResult> 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