【发布时间】:2017-02-06 03:45:08
【问题描述】:
我的应用程序中有一个 Ajax 表单。我想将事件传递给 OnBegin 函数,然后使用 event.preventdefault() 这将阻止表单提交,然后检查某些条件我正在尝试提交表单手动。但它不起作用,我无法弄清楚原因。
Ajax.BeginFrom:
@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;
}
}
【问题讨论】:
标签: javascript jquery asp.net-mvc forms ajax.beginform