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

172
Vistas
Confirmation dialog will not show when submitting form

I am trying to throw up a confirmation dialog before a user clicks delete.

 @using (Html.BeginForm("Delete", "Controller", new { viewModel.Id }, FormMethod.Post, null, new { onsubmit= "return confirm('Do you really want to submit the form?');", @style = "text-align: center" }))
 {
    <input type="submit" value="X" class="form-control btn btn-danger" />
 }

The form seems to be rendering as you would expect:

<form action="/admin/RiskProfile/Delete/24" method="post" onsubmit="return confirm('Do you really want to submit the form?');" style="text-align: center">   
        <input type="submit" value="X" class="form-control btn btn-danger">
        <input name="__RequestVerificationToken" type="hidden" value="CfDJ8O5vcsGUmyZOqz2RSFC3UgK8ICB1W1Ov79zW2-IkboTHIL_LvzQMkjy9s4JsbrA9fEXtE4YfWy1pULXxUk4VhKJc2V53WUuVYJwTB0gbBlxRmM8flrHnFvmtJ8Dr_6zPXmDkZW31Tga5pEiCPw1ebTQMbCLmbhzLKKf9jLErmbajbpUSpYUtZG5H_bMaXw3ptg">
</form>

When I click the button it simply submits the form without throwing up the confirmation dialog.

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

0

My knowledge of .net is limited, but it seems like you just need to prevent the default action from the form submission event. Here's some code to get you rolling, though it may not be perfect:

 @using (Html.BeginForm("Delete", "Controller", new { viewModel.Id }, FormMethod.Post, null, new { onsubmit= "onFormSubmit", @style = "text-align: center" }))
 {
    <input type="submit" value="X" class="form-control btn btn-danger" />
 }
function onFormSubmit (e) {
    e.preventDefault() // The default event action should be ignored
    return confirm('Do you really want to submit the form?');
}
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