【发布时间】:2021-02-16 19:59:16
【问题描述】:
我希望用户按下下载按钮。该按钮将调用一个 JQuery 函数,该函数将启动加载模式,运行 Url.Action 请求,然后在操作完成运行后立即停止模式。不幸的是,JS 启动然后停止我的模态,即使它还没有完成运行我的 Url.Action
代码:
$('#DownloadBtn').click(function () {
var modal = document.getElementById("myModal");
modal.style.display = "block"; // starts the loading modal display when button is pressed
location.href = '@Url.Action("Download", "Home")'; //action to download begins (this usually takes around 10 seconds to run through, that's why I want that modal running until the action is finished)
modal.style.display = "none"; //this switches to none before the above Action has even completed
}
【问题讨论】:
-
设置
location.href将导致当前页面被卸载,因此在此之后您无法对DOM 进行任何更改。无论如何都需要隐藏模式似乎几乎完全是多余的,因为传输页面的操作无论如何都会导致内容更新。
标签: javascript jquery asp.net-core-mvc modal-dialog