Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

269
Vistas
Asp.net Core MVC - IdentityUser Is Not Getting Deleted

I am working on an asp.net core mvc project and I am using ef-core with IdentityUser. I encountered an error while deleting the user. Previously the delete code was working fine. After I applied the javascript confirm box to confirm the delete operation, the confirm box appears but when I click on OK, it doesn't delete the user anyhow.I tried to remove the javascript code, but it still doesn't delete the user anyhow. Please do help.

Here is the code for the submit button and form tag :

<form method="post" asp-route-Id="@user.Id" asp-action="DeleteUser" asp-controller="Admin">
                                        <button type="submit" onclick="return DeleteU()" class="btn btn-danger w-100">
                                            <i class="fas fa-trash-alt"></i>
                                        </button>
                                    </form>

Here is the javascript code:

<script>
    function DeleteU() {
        var result = confirm("Are You Sure You Want To Delete The User?")
        if (result) {
            return true;
        }
        else {
            return false;
        }
    }
</script>

 

Here is the code of controller method :

 public async Task<IActionResult> DeleteUser(string Id)
        {
            var user = await _userManager.FindByIdAsync(Id);

            if (user == null)
            {
                return NotFound();
            }
            else
            {
                _db.Users.Remove(user);
                await _userManager.DeleteAsync(user);
                _db.SaveChanges();
                return RedirectToAction("UserMgmt");
            }

        }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Firstly you have to delete it using UserManager and it will automatically reflect in database `public async Task DeleteUser(string Id) { var user = await _userManager.FindByIdAsync(Id);

        if (user == null)
        {
            return NotFound();
        }
        else
        {
            var transaction = context.Database.BeginTransaction()
            await _userManager.DeleteAsync(user);
            await transaction.CommitAsync();
            return RedirectToAction("UserMgmt");
        }

    }.
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda