下载带有响应的项目 [英] Download Item With Response

查看:50
本文介绍了下载带有响应的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想允许客户端下载附件。这里的 attachment.AttachmentContent 是文件中的字节数组。当我单击按钮下载附件时,它将在下面运行此代码。但是我有以下脚本错误。我该怎么解决?

I want to allow client to download attachment. Here attachment.AttachmentContent is bytes array from file. When I click on the button to download attachment it runs this code below. But I have the following script error. What should I do to fix it ?


未捕获到Sys.WebForms.PageRequestManagerParserErrorException:
Sys.WebForms.PageRequestManagerParserErrorException:从服务器收到的消息
可能无法解析。导致此
错误的常见原因是:通过调用Response.Write(),
响应过滤器,HttpModules或服务器跟踪启用了对响应的修改。详细信息:
在' JFIF``附近解析时出错。

Uncaught Sys.WebForms.PageRequestManagerParserErrorException: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled. Details: Error parsing near '����JFIF``'.



Attachment attachment = _attachmentService.GetAttachmentBytesById(int.Parse(e.CommandArgument.ToString()));

Response.Clear();
Response.ClearHeaders();
Response.ContentType = "image/jpeg";
Response.AddHeader("Content-Disposition", "attachment; filename=\"" + "test.jpg" + "\"");
Response.OutputStream.Write(attachment.AttachmentContent, 0, attachment.AttachmentContent.Length);
Response.End();


推荐答案

似乎您正在部分下载此文件。

Seems you are sending this file download in partial response.

最常见的原因是您的下载按钮位于UpdatePanel中。

The most common cause if that your download button is inside an UpdatePanel.

文件只能在以下位置发送:完整的PostBack。

Files can only be send on a full PostBack.

您可以将下载按钮设置为PostBack触发器来解决此问题。

You can set your download button as a PostBack trigger to solve this.

<Triggers>
    <asp:PostBackTrigger ControlID="Download_Click">
</Triggers>

这篇关于下载带有响应的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆