Joe Pool

Joe Pool

  • 1.7k
  • 58
  • 1k

How do I trigger 'ajaxStart' and 'ajaxStop' from Html.BeginForm?

Feb 15 2023 8:31 PM

I am working with a large project that is built with ASP.NET MVC 5.

I have a Wait Cursor that I want to display whenever a query is run. Some queries are called with jQuery syntax:

`$.get("@Url.Action("BigQuery", "Home"));`

But most are called with Html.BeginForm syntax:

`@using (Html.BeginForm("BigQuery", "Home", FormMethod.Post))`

Using the jQuery syntax, I can show and hide the Wait Cursor:

```
    $(document).ready(function () {
        $('#waitDiv').hide();
        $(document).ajaxStart(function () {
            $('#waitDiv').show();
        })
        $(document).ajaxStop(function () {
            $('#waitDiv').hide();
        });
    });
```

But, these methods are not triggered with the Html.BeginForm, and they account for over 90% of the calls in the corporate website.

What can I do to allow the Wait Cursor to show and hide with the Html.BeginForm techniques?


Answers (5)