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

177
Views
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 answers
Answer question

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