我有一个表单,即使验证失败,它仍会提交给控制器。
jQuery:
$(document).ready(function () {
$('#commentForm').validate();
});
$(function () {
$('#commentForm').submit(function () {
$('#result').empty();
$.ajax({
url: "Action/Index",
type: "POST",
data: {
name: $('#name').val(),
emailAddress: $('#emailAddress').val()
},
success: function (result) {
alert(result);
}
}
});
return false;
});
});
html:
<form class="cmxform" id="commentForm">
<fieldset>
<div id="contactUsName">Your Name<br />
<input type="text" id="name" class="required" />
</div>
<div id="contactUsEmail">Email Address<br />
<input type="text" id="emailAddress" class="required email" />
</div>
</fieldset>
</form>