The send handler does not start after verification. He works before. Try:
$('form').submit(function () { alert('validation hasn\'t run yet at this point => see there is no red color over your form input fields yet'); if ($(this).valid()) { alert('the form is valid'); } else { alert('the form is not valid'); } });
UPDATE:
After a revised question, I still cannot reproduce the problem. Here is my model:
public class MyModel { [Required] public string Name { get; set; } }
and here is my opinion:
@model MyModel <script src="@Url.Content("~/Scripts/jquery.validate.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")" type="text/javascript"></script> @using (Html.BeginForm(null, null, FormMethod.Post, new { })) { @Html.EditorFor(x => x.Name) @Html.ValidationMessageFor(x => x.Name) <input type="submit" value="OK" /> } <script type="text/javascript"> $('form').submit(function () { $('#Name').val('some value'); }); </script>
Now, if I leave the "Name" field empty and submit the form, the new value will be correctly assigned and the form will be successfully submitted to the server without any errors. If I delete the line $('#Name').val('some value'); which assigns a new value, and try sending the form to empty client-side validation triggers on the client side and the form will not be submitted.
source share