2011-07-08 39 views
0

我一直在使用這個鏈接作爲開發我的WebGrid的參考(http://msdn.microsoft.com/en-us/magazine/hh288075.aspx)。MVC3 WebGrid:在排序或分頁時,是否有方法在調用Controller Action方法之前調用JavaScript方法?

目前發生的事情是,我的WebGrid加載,我可以異步頁面和排序就好...沒有問題。什麼是惱人的是,一旦我點擊頁面或排序,用戶不知道任何事情正在發生。

所以我在找的是一種在控制器的動作方法被調用之前調用一個javascript函數(或者任何其他的東西)的方法,這樣我就可以讓用戶知道正在做的工作來返回它們下一頁,排序等等。

我不確定如果我只是錯過了一些東西,但任何幫助將不勝感激。

回答

2

您可以使用.ajaxSend().ajaxComplete()的方法來顯示和AJAX請求中隱藏了一些微調:

$(function() { 
    $('#grid').ajaxSend(function() { 
     // this will be called before the AJAX request is sent 
     // here you can show some spinner 
     $('body').append('<div id="spinner">Loading ...</div>'); 
    }).ajaxComplete(function() { 
     // this will be called after the AJAX request completes and 
     // could be used to hide the spinner 
     $('#spinner').remove(); 
    }); 
}); 
相關問題