Ajax.BeginForm not hiding loading element when onBegin fails

本小妞迷上赌 提交于 2020-01-02 17:56:58

问题


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.


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/1164251/ajax-beginform-not-hiding-loading-element-when-onbegin-fails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!