public FileResult CustomerContract_Download(int Id)
{
var s = 获取文件的Byte[]类型
var r = File(s, 字符串类型填写文件的MIME类型);
return r;
}
$.ajax({
url: 接口地址,
type: "post",
async: true,
cache: false,
xhrFields: { responseType: "blob" },
data: { Id: id },
success: function (res) {
console.log(res);
if (res.code==1) {
layer.alert(res.msg, { icon: 5 });
} else {
const blob = new Blob([res]);
const fileName = 文件名称(带文件格式,如:1.zip);
const linkNode = document.createElement('a');
linkNode.download = fileName;
linkNode.style.display = 'none';
linkNode.href = URL.createObjectURL(blob);
document.body.appendChild(linkNode);
linkNode.click();
URL.revokeObjectURL(linkNode.href);
document.body.removeChild(linkNode);
}
}
});