0

MVC Form

@using(Html.BeginForm("Student", "Manage", FormMethod.Post, new { id = "studentForm" }))

Jquery

 $("#studentForm").submit(function (e) {
           // showing loading  spinner here
 });

Here how to show and hide the loading spinner? Is there any success and failure callbacks for the above jquery submit event. Please advice. Thanks!

Dylan
  • 137
  • 1
  • 2
  • 10
  • Possible duplicate of https://stackoverflow.com/a/30196610/4588756 – Hossein Feb 24 '19 at 09:13
  • I think its not a duplicate. I want to know success and failure events for jquery submit event. – Dylan Feb 24 '19 at 09:49
  • 1
    Possible duplicate of [How to do a Jquery Callback after form submit?](https://stackoverflow.com/questions/11534690/how-to-do-a-jquery-callback-after-form-submit) – mvermef Feb 24 '19 at 09:55

2 Answers2

1

When you submit a form that way, that cause a complete page callback to server. so there is no chance to show and hide a spinner. if you want async callback it is better to use $.ajax so you have more control on process life cycle. also there is a nice plugin you can use more close to your own way: https://github.com/claviska/jquery-ajaxSubmit

Mazdak
  • 650
  • 5
  • 13
0

I have found the answer:

$("#StudentForm").submit(function (event) {
            var isValid = $('#StudentForm').valid();
            if (isValid) {
                // Showing Spinner Here
            }
        });

Thanks!

Dylan
  • 137
  • 1
  • 2
  • 10