开发者

Ajax.BeginForm show loadingElementId when OnBegin return false

开发者 https://www.devze.com 2022-12-15 04:54 出处:网络
Hello I\'m having the same problem from this post: Ajax.BeginForm not hiding loading element when onBegin fails but I have not found how to solve it yet.

Hello I'm having the same problem from this post:

Ajax.BeginForm not hiding loading element when onBegin fails but I have not found how to solve it yet.

Basically when I use Ajax.BeginForm with a OnBegin function and this function returns false, the loading elementID is still shown and it nev开发者_JS百科er hides again.

This is the code I'm testing it with:

function isValid() {
    return false
} 


<% using (Ajax.BeginForm("LogIn", "Security", new { ReturnUrl = Request["ReturnUrl"] }
       , new AjaxOptions { UpdateTargetId = "resultErrors", OnBegin = "isValid", LoadingElementId = "updatePanel" }))
{ %>


I don't remember exactly the solution, i decided a long time ago that it was much better to write my own and plain Html to handle Ajax calls.

If you want you can post your code here and i can show you how to do it with JQuery.

Now if you want to stick with this solution you can still use JQuery to hide the element manually like this:

<% using (Ajax.BeginForm("LogIn", "Security", new { ReturnUrl = Request["ReturnUrl"] }
   , new AjaxOptions { UpdateTargetId = "resultErrors", OnBegin = "isValid", LoadingElementId = "updatePanel" }))
{ %>

<script type="text/javascript" language="javascript" src="<%=Url.Content("~/Scripts/jquery-1.4.1.js") %>">//Jquery reference
</script>

<script type="text/javascript" language="javascript">
   function isValid() {
       if (true) // In case i whant to return true
       {
           return true;
       }
       else // I whant to return false
       {
           $('#updatePanel').hide(); // Manually hide the LoadingElementId
           return false;
       }
   }    
</script>
0

精彩评论

暂无评论...
验证码 换一张
取 消