I'm using Razor Pages and seem to be struggling to display a confirmation message when a user clicks the delete button.
On my Index.cshtml I have:
<a asp-page-handler=Delete [email protected] id=deleteBtn class=btn bg-danger mr-1><i class=fas fa-trash-alt text-white></i></a>
These are generated as part of a foreach loop.
My delete method:
public async Task<IActionResult> OnGetDelete(Guid id)
{
if (id == null)
{
return NotFound();
}
var record = await _context.LoadTable.FindAsync(id);
if (record != null)
{
_context.LoadTable.Remove(record);
await _context.SaveChangesAsync();
}
return RedirectToPage(./Index);
}
I'm using Bootstrap so ideally would like to use it's modal to display the message. Displaying the message isn't the issue but rather I need to stop the method from firing until a user has confirmed that that's what they want to do, and with Razor Pages, I seem to be struggling.
My thoughts were to have the delete button in the modal and the delete button shows the modal instead but I'm unsure how to pass @item.Id with it.
Alternatively use JavaScript to intercept the button click?