jquery - 无法下载与 href url 操作一起使用的文件形式的 JavaScript
问题描述
我有一个代码,当我使用锚标记时,当我尝试使用 JQuery 调用按钮单击时,它正在工作,它没有下载文件
function DownloadFile() {
var data = {
'tableName': $("#tableName").val(),
'attachmentId': $("#attachmentId").val()
};
$.ajax({
url: fileUrl,
type: "POST",
data: data,
success: function (res) {
}
});
}
相同的代码适用于 href 标记上的 url.action,如下所示
<a class="mr-2" href="@Url.Action("Index","Document",new { @tableName = "otherVessel",@attachmentId = otherVessel.AttachmentId})"> @otherVessel.AttachmentName</a>
我的控制器代码如下
public ActionResult Index(string tableName, int attachmentId)
{
AttachmentRepository attachmentRepository = new AttachmentRepository();
var result = attachmentRepository.GetDocument(tableName, attachmentId);
var cd = new System.Net.Mime.ContentDisposition
{
FileName = result.AttachmentName,
Inline = false,
};
Response.AppendHeader("Content-Disposition", cd.ToString());
return File(result.AttachmentData, result.AttachmentType);
}
解决方案
推荐阅读
- python - 如何将函数的路径分配给使用 openpyxl 创建的 excel?
- python - 使用 Xarray 组合 NetCDF 文件
- r - 使用 R 提取包含一组单词的句子
- apache-spark - 在 spark 中使用动态列名
- python - 在 Heroku 上从 github 构建被卡住,没有任何行被写入
- python - conda 中的新环境可以从基础环境继承特定的包吗
- javascript - 如何从 eslint 中排除文档文件夹
- c# - 从 ASP.NET 中的一个表映射两个实体
- sharepoint - 在 SharePoint 列表中获取 SMS 响应
- java - 如何在android中对api响应进行分组