using asp.net mvc2, Data Annotations, MicrosoftAjax.js,MicrosoftMvcValidation.js, jquery for ajax
I have contact form and i am using Data Annotations for the ContactFormModel
.
<% Html.EnableClientValidation(); %>
to top of the form.
When i click the submit button client validation works perfectly. Now i have changed my mind and want to post the form with jQuery.Ajax.
This time i want to accomplish this.
- Click submit button.
- MicrosoftMVCValidation does the client validation and renders the errors on the clientside.
- If Model is valid i meant if the validation passed i want my jQuery ajax to get involved.
But when i clicked the submit button both ajax post 开发者_运维问答and mvc client validation works. How can i get the things in right order.
1.Mvc Client validation
2. Then jQuery.Ajax Post. var myForm = $("#MainForm");
var formContext = myForm[0]['__MVC_FormValidation'];
var errors;
if (formContext) {
// validate the form
errors = formContext.validate("submit");
}
if (!formContext || errors.length == 0) {
// no errors so submit to server
...
}
精彩评论