I realize that variations on this question have been asked before. The best answer I have found is at
File download in Asp.Net MVC 2
But trying to follow those instructions did not solve the problem for me.
Long story short, the file is being retrieved correctly, the name, path and mime type are all correct, and no errors are thrown. No errors are thrown by the javascript on the client-side either.
The C# code that gets the file looks like this:
[HttpPost]
public FileResult DownloadFile(int fileId)
{
... get the file and file info
return File(fileBytes, fileMimeType, fileName);
}
The javascript looks like this:
... set up for post here
$.post(settings.actions.downloadFile, {fileId: fileIdVar});
As I was saying, the post returns and nothing happens.
I have tried changing the post to a get, and the result was the same.
I have tried setting up a callback function that sets document.location.href to some random url on return from the download, but that just takes my browser to the page I specified. I cannot understand, from the explanation given in the link I provided, that is
"...Use document.location.href = ... to tell the browser to go to the url for downloading the file. It'll see the content disposition header and will display it as a download not as a page..."
What I'm supposed to point my browser to. document.location.href doesn't accept data, so I can't use it on its own, and using post without document.location.href returns nothing.
What could I be doing wrong?
Big thanks to responders for their time!