I am using Html.BeginForm to submit my form and Html.ValidationSummary for validating. Now I would like to do an action in javascript (launch a reload animation) only if the form is submitted succesfully. My problem is, that the action is fired even when the form of the validation is is not validated successfully. Is it possible to find out if the validation was successful or not?
Here is my code:
@using (Html.BeginForm("AddRequest", "Manage", FormMethod.Post, new { id="addRequest"}))
{
<div class="modal-body">
<div>@Html.ValidationSummary(false, "", new { id = "requestValidationSummary" @*onsubmit = "return viewNewRequestLoader()"*@ })</div>
<div class="form-horizontal">
<div class="form-group">
@Html.LabelFor(m => m.DateFrom, "Datum od:", new { id = "labelReqDateFrom" })
@Html.TextBoxFor(m => m.DateFrom, new { @class = "date-picker form-control", Value = "", type = "date", id = "requestDateFrom" })
@Html.LabelFor(m => m.DateTo, "Datum do:", new { id = "labelReqDateTo" })
@Html.TextBoxFor(m => m.DateTo, new { @class = "date-picker form-control", Value = "", type = "date", id = "requestDateTo" })
@Html.LabelFor(m => m.Description, "Popis:")
@Html.TextBoxFor(m => m.Description, new { @class = "form-control", Value = "", Id = "RequestDescription" })
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-light" data-dismiss="modal">Zavřít</button>
<button type="submit" class="btn btn-primary">Potvrdit</button>
</div>
}
and js code:
$("#addRequest").submit(function (event) {
$('.modal').modal('hide');
$("#ajaxLoader").fadeIn(300);
});