views:

531

answers:

1

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.

A: 

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

Sneakyness
This is pretty much what I am having to do. I was just wondering if anyone knew why the helper was not doing this for me.
Sam Wessel
I don't think the helper would do that. However I do think your code might be set up wrong, is it possible to set the loadingelementid somewhere else?What does doValidation look like?
Sneakyness
The helper is supposed to do that. Otherwise what is the point of having the loadingElementId option, if it is not compatible with all the callbacks? Seems to me like a bug/shortcoming in the ajax helper. Shame.
Sam Wessel