リスト ビューがあり、すべてのデータを txt ファイルとしてエクスポートしたいと考えています。要件として、[エクスポート] ボタンをクリックして 3 つの txt ファイルを作成する必要があります。これらのファイルを生成し、zip ファイルとしてダウンロードするコントローラー アクションがあります。[エクスポート] ボタンをクリックすると、アクション「ExportFiles」がトリガーされます。同時に、ビューを更新したいので、アクション「リスト」にリダイレクトしたいと思います。
しかし、問題は、両方のタスクを同時に実行できないことです。どうすればそれができますか?
これは私のコードです。
public virtual ActionResult List()
{
// Code : showing my list
return view();
}
public virtual ActionResult ExportFiles()
{
// Code : Generating files
return new ZipResult(filePath, fileName + ".zip");
// HERE I WANT TO REFRESH MY VIEW
}
public class ZipResult : ActionResult
{
private readonly string _filePath;
public string Filename { get; set; }
public ZipResult(string filePath, string fileName)
{
_filePath = filePath;
Filename = fileName;
}
public override void ExecuteResult(ControllerContext context)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
var response = context.HttpContext.Response;
response.ContentType = "application/gzip";
using (var zip = new ZipFile())
{
zip.AddFile(_filePath);
zip.Save(response.OutputStream);
var cd = new ContentDisposition
{
FileName = Filename,
Inline = false
};
response.Headers.Add("Content-Disposition", cd.ToString());
}
}
}