【发布时间】:2021-06-20 23:44:01
【问题描述】:
当有人试图删除将链接更改为“localhost:0000/users/delete/3”的用户时,我该怎么做?我只想在单击删除图标后能够删除用户。 这是删除图标的代码:
<a asp-action="Delete" asp-route-id="@item.ID" onclick="return confirm('Are you sure you want to remove the user?')"><i class="fa fa-trash-o"></i></a>
这是我的删除操作:
public async Task<IActionResult> Delete(int id)
{
var usersModel = await _context.Users.FindAsync(id);
if (usersModel != null)
{
_context.Users.Remove(usersModel);
await _context.SaveChangesAsync();
}
return RedirectToAction("Index", "Users");
}
【问题讨论】:
-
您搜索类似stackoverflow.com/questions/47935231/… 的内容?
-
难道没有办法让您从链接重定向,但如果您点击按钮就不会?
标签: asp.net asp.net-mvc asp.net-core hyperlink identity