Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

170
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda