I have a view page with model validations and client side validation enabled. I have a submit button which on click I have called a javascript function which uses jQuery for an AJAX call to the server..but I want to stop the AJAX action when client side validations fails. Any idea how to?
<% Html.EnableClientValidation(); %>
<% using (Html.BeginForm("", "", FormMethod.Post, new { @class = "hiajax" }))
{%>
<%= Html.ValidationSummary(true) %>
<div class="formRow">
<%if(Model.ListFacility.Count !=0){ %>
<%= Html.LabelFor(model => model.ListFacility)%><span class="err">*</span><br />
<%= Html.DropDownListFor(model => model.ListFacility, (SelectList)ViewData["FacilityBulletin"], new {onChange="updateSiteId()" })%>
<span class="err"> <%= Html.ValidationMessageFor(model => model.ListFacility) %></span>
<div class="clear">
</div>
<%} %>
<div class="formRow">
<%= Html.LabelFor(model => model.FacilityBulletin) %><span class="err">*</span><br />
<%= Html.TextAreaFor(model => model.FacilityBulletin, new { @class = "tinymce" })%>
<span class="err"> <%= Html.ValidationMessageFor(model => model.FacilityBulletin) %></span>
<div class="clear" />
</div>
<div class="formRow">
<%=Html.CheckBoxFor(model=>model.Active, new { style = "float: left; margin-right: 10px;" })%>
<span style="float: left; padding-top: 1px;">Active</span>
<%=Html.HiddenFor(model=>model.SiteId) %>
</div>
<div class="formRow">
<input type="image" name="Save" src='<% =Url.Content("~/images/btn_save.png") %>' onclick="SaveBulletin();" />
</div>
<% } %>
</div>
Here is my JavaScript:
function SaveBulletin() {
tinyMCE.triggerSave();
$.ajax({
type: 'POST',
url: "FacilityBulletin/FacilityBulletin/SaveBulletin",
data: $("form.hiajax").serialize(),
success: function (data) { alert(data); }
});
}
Please help.