asp.net-mvc - ASP.NET MVC 3 Jquery 模态弹出窗口 - 显示加载图标

标签 asp.net-mvc popup modal-dialog

各位,

我有 ASP.NET MVC 3 应用程序,并且下面有以下 JQuery 脚本来显示模式弹出窗口。以下脚本能够显示模式对话框。但是,我想在模式对话框打开时加载加载图标。你知道我该怎么做吗?

<%= Html.ActionLink("Details", "ProductShipping", "OnlineStore", new { ProductGUID = Html.Encode(Model.GUID) }, new { @class = "EditShippinglink", title = "Edit Product Shipping", data_dialog_id = "EditProductShipping", data_dialog_title = "Shipping Method" })%>

JQuery

$(".EditShippinglink").live("click", function (e) {
            $.ajaxSetup({ cache: false });
            e.preventDefault();
            var $loading = $('<img src="/Content/ajax-loader.gif" alt="loading" class="ui-loading-icon">');
            $("<div></div>")
                    .addClass("dialog")
                    .attr("id", $(this)
                    .attr("data-dialog-id"))
                    .appendTo("body")
                    .dialog({
                        title: $(this).attr("data-dialog-title"),
                        close: function () { $(this).remove() },
                        width: 900,
                        modal: true,
                        minHeight: 500,
                        show: 'fade',
                        hide: 'fade',
                        resizable: 'false'
                    })
                    .load(this.href);
        });

最佳答案

将模式对话框的初始 HTML 设置为您想要显示的内容,直到 ajax 请求完成并更改弹出窗口的内容。

而不是从一个空的 div 开始,$('<div></div>') ,使用加载了您想要在加载时显示的 html 的 div。

@Html.ActionLink("Item Details", "Details", "Home", new { id = 1 }, new { @class = "EditShippinglink", title = "Edit Product Shipping", data_dialog_title = "Shipping Method" })
<div id="my-dialog" style="display:none;">
    <div id="my-dialog-content"></div>
    <div id="my-dialog-progress" style="display:none;"><img src="@Url.Content("~/Content/ajax-loader.gif")" alt="loading" class="ui-loading-icon"></div>
</div>

<script type="text/javascript">
    var theDialog = $('#my-dialog').dialog({
        autoOpen: false,
        modal: true,
        closeOnEscape: false,
        width: 900,
        modal: true,
        minHeight: 500,
        show: 'fade',
        hide: 'fade',
        resizable: 'false'
    });
    var myDialogProgress = $('#my-dialog-progress');
    var myDialogContent = $('#my-dialog-content');
    $(".EditShippinglink").on("click", function (e) {
        $.ajaxSetup({ cache: false });
        e.preventDefault();

        myDialogProgress.show();
        theDialog.dialog('open');
        theDialog.dialog('option', 'title', $(this).attr("data-dialog-title"));

        //clear content before showing again
        myDialogContent.html('');

        $.ajax({
            type: 'get',
            url: this.href,
            dataType: 'html',
            error: function (jqXHR, textStatus, errorThrown) {
                //do something about the error
            },
            success: function (data) {
                //hide the progress spinner and show the html
                myDialogProgress.hide();
                myDialogContent.html(data);
            },
            complete: function () {
                //do some other completion maintenance
            }
        });
    });

</script>

然后,当显示对话框但仍在等待加载完成时,将显示加载 gif。一旦操作完成,加载将覆盖动画加载gif html。

关于asp.net-mvc - ASP.NET MVC 3 Jquery 模态弹出窗口 - 显示加载图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9297196/

相关文章:

iphone - 创建一个仅包含 TextView /字符串和按钮 SWIFT ios 8 的弹出窗口

jquery - 控制加/减只影响当前窗口

twitter-bootstrap - 当将值作为参数传递给 addin 时将值传递给 ember.js 组件(例如 ember-bootstrap-modals-manager)

c# - C# -ASP.NET 中的一些性能 [注意事项/注意事项] 是什么

asp.net-mvc - 如何在我的 MVC 项目后面的代码中访问服务器端控件?

javascript - 停止子 DIV 从其父页面继承样式

wpf - 使用服务定位器的 MVVM 模态对话框

javascript - 为什么我的模态框不会在窗口的正中央打开?

c# - 在 MVC 中将 JSON 字符串转换为 JsonResult

asp.net-mvc - 为什么人们在 MVC 中使用 Web API Controller