如何在asp.net core mvc 6中使用客户端确认删除功能

时间:2017-02-03 17:27:05

标签: asp.net-core-mvc entity-framework-core asp.net-core-1.0

我有删除方法,但我不知道如何删除客户确认, 我有一个删除方法

public async Task<IActionResult> Delete(int? id, bool? saveChangesError = false)
{
    if (id == null)
    {
        return NotFound();
    }

    var student = await _context.userAccount
        .AsNoTracking()
        .SingleOrDefaultAsync(m => m.UserID == id);
    if (student == null)
    {
        return NotFound();
    }

    if (saveChangesError.GetValueOrDefault())
    {
        ViewData["ErrorMessage"] =
            "Delete failed. Try again, and if the problem persists " +
            "see your system administrator.";
    }

    return View();
}

// POST: Students/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(int id)
{
    try
    {
        UserAccount accToDelete = new UserAccount() { UserID = id };
        _context.Entry(accToDelete).State = EntityState.Deleted;
        await _context.SaveChangesAsync();
        return RedirectToAction("Index");
    }
    catch (DbUpdateException /* ex */)
    {
        //Log the error (uncomment ex variable name and write a log.)
        return RedirectToAction("Delete", new { id = id, saveChangesError = true });
    }
}

如何在asp.net核心mvc 6中首次点击客户端确认。 任何新想法或任何修改

0 个答案:

没有答案