XLS と PDF にエクスポートしようとしたときに同様の問題が発生しました。応答時間を改善するように見える唯一のことは、次のようなファイルを生成するクラスから直接応答を送信することでした。
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.BufferOutput = true;
HttpContext.Current.Response.ContentType = "application/pdf";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + file + ".pdf");
HttpContext.Current.Response.BinaryWrite(stream.ToArray());
HttpContext.Current.Response.Flush();
stream.Close();
HttpContext.Current.Response.End();
しかし、これを行うと"not all code paths return a value"
、ActionMethod から が取得されます。これを回避するために、以下を送信するだけです。
return new EmptyResult();
この最後の行は、メソッドで直接リクエストを終了するため、実際には実行されません。