I have an Ajax form in my application.I want to pass the event to OnBegin
function and then use event.preventdefault()
which will stop the form from submitting and then on checking some conditions I'm trying to submit the form manually.But it's not working and I'm not able to make out why.
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:
function OnBeginForm(e) {
e.preventDefault();
if(some condition){
$('#Ajax_form').submit();
}
else{
return false;
}
}