I am having trouble with client side validation when using Ajax and jQuery to handle a form sumission when using ASP.NET MVC 3.
Checking if the model is valid on the server side works, however the following snippet does not trigger the client side valiation.
Am I missing something?
@model ViewModels.LeadDetailModelCore
@{using (Html.BeginForm("UpdateCore", "Leads", new { area = "Telesales" }, FormMethod.Post, new { id = "coreSave" }))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
@Html.HiddenFor(model => model.Lead_ID)
@Html.LabelFor(model => model.LeadStatus_ID)
@Html.DropDownListFor(model => model.LeadStatus_ID, new SelectList(Model.LeadStatuses, "LeadStatus_ID", "LeadStatus_Name"), "-- Please select a status --")
@Html.ValidationMessageFor(model => model.LeadSource_ID)
}}
<script type="text/javascript">
// NOTE ADD
$(function () {
$('#coreSave').die().live("submit", function (e) {
e.preventDefault();
var form = $(this);
var val = form.validate()
if (val.valid()) {
$("#ProgressDialog").dialog("open");
// post via ajax
}
return false;
});
});
</script>