比較的単純なものに苦労している古い MVC 1.0 アプリケーションがあります。
- ユーザーがファイルをアップロードできるようにするビューがあります。
- サーバー側の処理が続行されます。
- 最後に、新しいファイルが生成され、クライアントのマシンに自動的にダウンロードされます。
ステップ1と2が機能しています。最後のステップが機能しません。これが私のコントローラーです:
[AcceptVerbs(HttpVerbs.Post)]
public ViewResult SomeImporter(HttpPostedFileBase attachment, FormCollection formCollection, string submitButton, string fileName
{
if (submitButton.Equals("Import"))
{
byte[] fileBytes = ImportData(fileName, new CompanyExcelColumnData());
if (fileBytes != null)
{
RedirectToAction("DownloadFile", "ControllerName", new { fileBytes = fileBytes});
}
return View();
}
throw new ArgumentException("Value not valid", "submitButton");
}
public FileContentResult DownloadFile(byte[] fileBytes)
{
return File(
fileBytes,
"application/ms-excel",
string.Format("Filexyz {0}", DateTime.Now.ToString("yyyyMMdd HHmm")));
}
コードは次のように実行されます。
RedirectToAction("DownloadFile", "ControllerName", new { fileBytes = fileBytes});
しかし、ファイルはダウンロードされません。提案を歓迎し、事前に感謝します。