简体   繁体   English

加载部分视图(AJAX)时应隐藏MVC视图页

[英]MVC View Page should hide while Partial View (AJAX) Loading

I have a drop down list, when I change the drop down list a telerik tree will be loading which is in a partial view and ajax loading bar appears in the tree content only. 我有一个下拉列表,当我更改下拉列表时,将在部分视图中加载telerik树,并且ajax加载栏仅出现在树内容中。 But I want to disable the page (user should not be able to use the page but he should see the page) while the content is loading and show the user a "loading....." screen. 但是我想在内容加载时禁用页面(用户应该不能使用该页面,但他应该看到该页面),并向用户显示“正在加载...”屏幕。

也许您可以使用BlockUI

If you use MVC's Ajax.BeginForm to do your ajax call back (rather than jquery) you can use the built in AjaxOption called LoadingElementId . 如果使用MVC的Ajax.BeginForm进行ajax回调(而不是jquery),则可以使用内置的AjaxOption称为LoadingElementId The downside is that it will require you to use a form to post instead of using $.ajax() . 不利之处在于,这将要求您使用表单发布而不是使用$.ajax() In the form you have to have an invisible button and the onchange event for the dropdown would have to build the form data in hidden fields and then issue a click event to the hidden button. 在表单中,您必须具有一个不可见的按钮,并且下拉菜单的onchange事件将必须在隐藏字段中构建表单数据,然后向隐藏按钮发出click事件。

The other approach is to toss a div up like this: 另一种方法是像这样折腾div:

<div id="loading-pane">
    <img src='<%: Url.Content("~/Content/Images/ajax-loader.gif") %>' />
</div>

and then css like this 然后像这样的CSS

#loading-pane { display:none; opacity: 0.8;  position: fixed; top: 0; left: 0; 
    width: 100%; height: 100%; filter: alpha(opacity=80); -moz-opacity: 0.8; 
    z-index: 999998; background-color: #ffffff; }
#loading-pane img { position: absolute; top: 40%; left: 47%; z-index: 999999; }

then something like this 然后像这样

$('#MyDropDown').change(function() {  
    $('#loading-pane').show();

    $.ajax({
        success: function() {
            $('#loading-pane').hide();
        }
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM