[英]Confirmation dialog will not show when submitting form
我試圖在用戶單擊刪除之前彈出一個確認對話框。
@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" />
}
表單似乎按照您的預期呈現:
<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>
當我單擊按鈕時,它只是提交表單而不會彈出確認對話框。
我對 .net 的了解有限,但似乎您只需要防止表單提交事件的默認操作即可。 這里有一些代碼可以讓你滾動,盡管它可能並不完美:
@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?');
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.