I have an old MVC 1.0 application that I am struggling with something relatively simple.
- I have a view that allows the user to upload a file.
- Some server side processing goes on.
- Finally, a new file is generated and downloads automatically to the client's machine.
I have steps 1 and 2 working. I can not get the final step to work. Here is my controller:
[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")));
}
The code executes:
RedirectToAction("DownloadFile", "ControllerName", new { fileBytes = fileBytes});
but the file does not download. Suggestions welcome and thanks in advance.