正在创建并返回 FileContentResult,但没有文件正在下载

FileContentResult is being created and returned, but no file is being downloaded

我正在为 asp.net 核心网络应用程序设计一个页面,允许用户设计一个对象,并在按下按钮时为其下载 json。为了做到这一点,按钮使用 jquery 和 ajax 来点击以下控制器方法:

// 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
    };
}

ajax请求中的.done(function() {得到运行,没有错误。因此,它似乎按预期工作。但是 文件没有下载

我已经在多个浏览器(Chrome、Firefox、Edge,甚至 IE)上对此进行了测试,并关闭了所有安全设置和拦截器。 None 这些更改中的任何一个都产生了影响,所以我很困惑。

端点上提供的代码是正确的,但是需要在 ajax/js 端进行处理才能真正下载文件;因为目前它只是返回并且什么都不做。

可在此处找到多个非常详细的参考资料:Handle file download from ajax post