The reason why you are unable to download the file is that you are using AJAX async request. An AJAX response cannot contain a file download. You can try something like this in your controller:
public ActionResult Index(...) {
var fileName = GenerateReport();
// store the file name somewhere on the server - do NOT pass it through the URL.
this.TempData["DownloadFileName"] = fileName;
this.TempData["DownloadContentType"] = "application/vnd.ms-excel";
this.TempData.Keep("DownloadFileName");
this.TempData.Keep("DownloadContentType");
return new JavaScriptResult() { Script = "document.location = \"" + this.Url.Action("Download") + "\";" };
}
public ActionResult Download() {
return File((string)this.TempData["DownloadFileName"], (string)this.TempData["DownloadContentType"], Path.GetFileName(filePath));
}
So your AJAX request will result in a redirect (cannot use RedirectToAction since that will cause to browser to redirect inside the AJAX request). This redirect will then instruct the browser to download the file in a classic request.