检查用户在 ASP.NET MVC 中下载文件时是否单击“保存”或“取消”按钮
我已经具有下载文件的功能。
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您无法捕获此事件。下载对话框的实现方式可能因浏览器而异。 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.
我建议您在采取行动之前这样做。就像您有一个带有下载和取消按钮的对话框。这样你就可以了解用户的意图。如果他点击下载,则表示正在下载,否则不要调用该操作。
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.