检查用户在 ASP.NET MVC 中下载文件时是否单击“保存”或“取消”按钮

发布于 2024-12-19 18:33:38 字数 416 浏览 3 评论 0原文

我已经具有下载文件的功能。

    public ActionResult Download(Guid AuthKey)
    {

        FileContentResult file = new FileContentResult(dataSet.Document, "Application/pdf");
        Response.ContentType = file.ContentType;
        Response.AppendHeader("Content-Disposition", "attachment; filename=" + dataSet.DocumentName + ".pdf");
        return file;
    }

如何检查用户是否单击下载对话框上的保存按钮或取消按钮?

I already have the functionality to download the file.

    public ActionResult Download(Guid AuthKey)
    {

        FileContentResult file = new FileContentResult(dataSet.Document, "Application/pdf");
        Response.ContentType = file.ContentType;
        Response.AppendHeader("Content-Disposition", "attachment; filename=" + dataSet.DocumentName + ".pdf");
        return file;
    }

How can i check if the user click the save button or cancel button on the download dialog box?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

暮年 2024-12-26 18:33:38

您无法捕获此事件。下载对话框的实现方式可能因浏览器而异。 HTML 规范中没有任何内容说明它应该是什么样子。在某些浏览器中甚至可能没有下载对话框。甚至可能没有“保存”或“取消”按钮。

You cannot capture this event. The way the download dialog is implemented might vary between browsers. There is nothing in the HTML specification that says how it should look like. In some browsers there might not even be a download dialog box. There might not even be Save or Cancel buttons.

吃素的狼 2024-12-26 18:33:38

我建议您在采取行动之前这样做。就像您有一个带有下载和取消按钮的对话框。这样你就可以了解用户的意图。如果他点击下载,则表示正在下载,否则不要调用该操作。

I would suggest you do that before calling the action. Like you have dialog with like download and cancel button. That way you can have the intentions of the user. If he click download he means downloading otherwise dont call the action.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文