1

asp.netページからファイルを送信しようとすると、このエラーが発生します。

Microsoft JScriptランタイムエラー:Sys.WebForms.PageRequestManagerParserErrorException:サーバーから受信したメッセージを解析できませんでした。

私のコード:

linkButton//これはグリッド上のaによってトリガーされます

    protected void Download(object sender, EventArgs e)
    {
        LinkButton lb = sender as LinkButton;

        // save file to temp
        Byte[] fileBytes = null;
        using (var db = new DbContext())
        {
            var id = Convert.ToInt32(lb.CommandArgument);
            fileBytes = db.Requests.Single(x => x.Id == id).File;
        }
        var filePath = Path.GetTempFileName();
        File.WriteAllBytes(filePath, fileBytes);

        // send
        FileInfo fi = new FileInfo(filePath);
        SendFile(fi);
    }

    private void SendFile(FileInfo file)
    {
        Response.ContentType = "application/zip";
        Response.WriteFile(file.FullName);
        Response.End();


// I also tried the code below I get the same error.

        //Response.Clear();
        //Response.ClearHeaders();
        //Response.ClearContent();
        //Response.AddHeader("Content-Disposition", "attachment; filename=PriceFile.zip");
        //Response.AddHeader("Content-Length", file.Length.ToString());
        //Response.ContentType = "application/zip";
        //Response.Flush();
        //Response.TransmitFile(file.FullName);
        //Response.End();
    }
4

2 に答える 2

2

更新パネルでクリックイベントを送信していると思います。ajaxを使用している場合は、ダウンロードボタンクリックイベントで全ページのポストバックを試してください

于 2012-12-11T10:52:21.790 に答える
0

ページのすべてのhtmlコンテンツをクリアし、最初の行(ページ)のみを残す必要があります

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="download.aspx.vb" Inherits="download" %>
于 2012-12-11T10:54:46.207 に答える