I am designing a page for an asp.net core web app that allows the user to design an object, and download the json for it upon a button press. In order to do this, the button uses jquery and ajax to hit the following controller method:
// GET: Missions/DownloadMission/5
[HttpGet, ActionName("DownloadMission")]
public FileContentResult DownloadMission(int id)
{
Mission toDownload = db.Missions.Find(id);
string json = JsonConvert.SerializeObject(toDownload);
string fileName = (toDownload.Title + ".txt");
string mimeType = "text/plain";
byte[] bytes = Encoding.ASCII.GetBytes(json);
return new FileContentResult(bytes, mimeType)
{
FileDownloadName = fileName
};
}
The .done(function() {
in the ajax request gets ran, and there are no errors. So, it is seemingly working as intended. However the file does not get downloaded.
I have tested this on multiple browsers (Chrome, Firefox, Edge, even IE), and turned off all security settings and blockers. None of these changes have effected anything, so I am stumped.