我的应用程序中有一个 Ajax 表单。我想将事件传递给OnBegin
函数,然后使用event.preventdefault()
这将阻止表单提交,然后在检查某些条件时我尝试手动提交表单。但它不起作用,我无法弄清楚为什么。
Ajax.BeginForm:
@using (Ajax.BeginForm("Update", "Project", false, new AjaxOptions { InsertionMode = InsertionMode.Replace,
HttpMethod = "Post",
OnBegin = "return OnBeginForm(event);",
OnSuccess = "OnSuccessArtwork(data);",
OnFailure = "OnFailureArtwork(data);" },
new { id = "Ajax_form" }))
{
// Here I have all the form elements //
<input type="submit" id="btnUpdate" class="btn02 pull-left" value="Update"/>
}
OnBegin 函数:
function OnBeginForm(e) {
e.preventDefault();
if(some condition){
$('#Ajax_form').submit();
}
else{
return false;
}
}
event.preventdefault() 这将阻止表单提交
您还可以使用return false;
停止表单提交,它基本上起到了以下效果event.preventdefault()
.
Check this https://stackoverflow.com/questions/1357118/event-preventdefault-vs-return-false.
下面的脚本应该适合你:
function OnBeginForm() {
if (some condition) {
return false;
}
}
希望有帮助:)
参考 https://stackoverflow.com/questions/41950483/mvc-trigger-submit-event-of-partial-view-in-main-view-using-jquery
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)