简体   繁体   English

在带有“请稍候”消息的新选项卡中打开表格

[英]Opening form in a new tab with 'Please wait' message

I'm trying to display PDF in a new tab after submitting a form. 提交表单后,我试图在新标签中显示PDF。 However, exporting a PDF takes a while so when users click export, new blank tab opens and there's no clear indication what is happening. 但是,导出PDF需要一段时间,因此当用户单击“导出”时,将打开新的空白标签,并且没有明确的指示。

To open form result in a new tab I'm using: 要打开表格会在新标签页中使用:

@using (Html.BeginForm("Export", "Reviews", FormMethod.Post, new { target = "_blank" } ))

and method in the controller is: 控制器中的方法是:

public FileStreamResult Export(int presentationID, int[] selectedViews)
{
    ...

    return new FileStreamResult(stream, "application/pdf");            
}

Is there a way to put a preloader in body of a new tab or open a tab only after PDF is ready to display? 有没有一种方法可以将预加载器放在新标签的正文中,或者仅在准备好显示PDF之后才打开标签? I don't want to use window.open() as this creates a popup which is blocked by default. 我不想使用window.open()因为这会创建一个默认情况下被阻止的弹出窗口。

Ajax File download Issue describes similiar problem but in my case I don't want the PDF to be downloaded but opened in a new tab. Ajax文件下载问题描述了类似的问题,但就我而言,我不希望下载PDF而是在新选项卡中打开PDF。

Maybe someone will find it helpful: 也许有人会觉得有帮助:

What I ended up doing is creating a new View which accepts values from the form. 我最终要做的是创建一个新视图,该视图接受表单中的值。 New view is opened in a new tab after form submit and contains just a 'please wait' message. 提交表单后,新视图将在新选项卡中打开,并且仅包含“请稍候”消息。 After document is loaded it immediately redirects to pdf export method using JavaScript. 加载文档后,它立即使用JavaScript重定向到pdf导出方法。 It's a bit dirty but works. 有点脏,但是可以用。

@{
    var url = Url.Action("Export", "Reviews", new { presentationID = Model.PresentationID });
    var sb = new System.Text.StringBuilder(url);

    foreach (var view in Model.SelectedViews)
    {
        sb.AppendFormat("&selectedViews={0}", view);
    }
}

<div class="export-wait">
    <i class="fa fa-spinner fa-spin fa-3x"></i>
    <h2>Please wait</h2>
    <p>
        Your report is being prepared, this may take a few minutes...
    </p>
</div>

<script>
    window.location = '@Html.Raw(sb.ToString())';
</script>

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

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