I have seen @Sparky's answer and sample jsFiddle to this question, and to my mind I have the right html and javascript in place, but still the browser is submitting the form.
I have this html:
@using (Html.BeginForm("Create", "ClientWarehouseRequest", FormMethod.Post, new { @class = "form-horizontal" }))
{
<!-- many form inputs here -->
<div class="buttons-wrap">
<input type="hidden" name="SubmitButtonValue" id="SubmitButtonValue" />
<input class="k-button" type="submit" value="Post" name="SubmitButton" />
@Html.ActionLink("Cancel", "Index", controllerName: null, routeValues: null, htmlAttributes: new { @class = "k-button", style = "vertical-align: bottom;" })
<input class="k-button" type="submit" value="Save" name="SubmitButton" />
</div>
}
with this javascript:
$(document).ready(function () {
$('form').validate({
submitHandler: function (form) {
var postingWindow = $("#postingDialogWindow").data("kendoWindow");
postingWindow.title("Posting Client Request...");
postingWindow.open();
$.ajax({
url: form.action,
type: form.method,
data: $(form).serialize()
})
.success(function (result) {
if (result.success) {
window.alerts.info(result.message, true);
window.location.replace(result.redirecturl);
}
else {
window.alerts.error(result.error);
}
})
.fail(function (result) {
//window.alerts.error(result);
var result = $.parseJSON(result.responseText);
window.alerts.error(result.errorMessage);
})
.always(function (data) {
postingWindow.close();
});
return false;
},
invalidHandler: function (event, validator) {
alert('invalid');
}
});
}
Yet when I click on the of the submit buttons, the browser is submitting the form as a full postback. I need the form to submit via the $.ajax call inside the validate() function instead. What am I missing?