2
votes

I'm using the Ajax.BeginForm helper in my MVC app. Here's a simplified example:

    <% using (Ajax.BeginForm("actionName", new { Controller = "controller" }, new AjaxOptions
           {
               OnBegin = "doValidation",
               LoadingElementId = "ajaxLoader"
           }))
       { %>

The problem is that if the OnBegin callback returns false, which correctly prevents the ajax call from being made, the loading element "ajaxLoader" is still displayed, and not hidden.

I've tried using the OnFailure and OnComplete callbacks, but neither of these are called if the OnBegin callback fails.

Interestingly the loading element is not displayed until after the OnBegin function has returned.

I can get around this by explicitly showing and hiding the ajax loading element in custom javascript functions, but this seems like something the helper should really take care of for me.

2

2 Answers

0
votes

I would try running an if function to only display the ajaxLoader if the callback returns true.

0
votes

try setting the display style on the loading div to none. Ex. ..your loading pic