Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

169
Views
El cuadro de diálogo de confirmación no se mostrará al enviar el formulario

Estoy tratando de mostrar un cuadro de diálogo de confirmación antes de que un usuario haga clic en eliminar.

 @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" /> }

El formulario parece estar renderizándose como era de esperar:

 <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>

Cuando hago clic en el botón, simplemente envía el formulario sin mostrar el cuadro de diálogo de confirmación.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Mi conocimiento de .net es limitado, pero parece que solo necesita evitar la acción predeterminada del evento de envío del formulario. Aquí hay un código para ponerte en marcha, aunque puede que no sea perfecto:

 @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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!