This has been asked and answered 100 times, and I have read them all, yet still my form submits after failing validation. I found a reference to not using jquery.validate higher than 1.9.0, so I rolled back to that (had been using 1.11) but no change.
If i submit with an invalid form (nothing filled out) the error messages appear, then the form submits.
I have successfully implemented validation a couple times in the past, and I can't see what is different about this time. I need to take a break from banging my head against this, hoping a fresh pair of eyes may see something.
--Scripts:
<script src="@Url.Content("~/Scripts/jquery-1.9.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-ui-1.10.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
Model:
[Display(Name = "First Name *")]
[StringLength(20)]
[Required(ErrorMessage = "Required.")]
public string FirstName { get; set; }
[Remote("CheckDuplicatePerson", "Validation", AdditionalFields = "FirstName", ErrorMessage="Person Exists")]
[Display(Name = "Last Name *")]
[StringLength(30)]
[Required(ErrorMessage = "Required.")]
public string LastName { get; set; }
View:
<div class="PersonForm">
@using (Html.BeginForm("AddPerson", "Person", FormMethod.Post))
{ @Html.ValidationSummary(true)
<div id="editor-left">
<div class="formGroup">
<div class="editor-label">
@Html.LabelFor(model => model.FirstName)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.FirstName) <br />
@Html.ValidationMessageFor(model => model.FirstName)
</div>
</div>
<div class="formGroup">
<div class="editor-label">
@Html.LabelFor(model => model.MiddleName)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.MiddleName)
</div>
</div>
<div class="formGroup">
<div class="editor-label">
@Html.LabelFor(model => model.LastName)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.LastName) <br />
@Html.ValidationMessageFor(model => model.LastName)
</div>
</div>
<div class="controls"><hr />
<input type="submit" class="skbutton" value="Next Page" />
</div>
}
</div>
UPDATE:
Get a JS Error in the jquery 1.9.1 file on this peice of code:
parseJSON: function( data ) {
// Attempt to parse using the native JSON parser first
if ( window.JSON && window.JSON.parse ) {
return window.JSON.parse( data );
}