必须下载文件,要么保留在当前页面上,要么打开一个新文件。告诉我该怎么做。这是已经完成的事情。
public FileResult DownloadFile(int id)
{
FilesDB filesDB = _context.FilesDB.Find(id);
filesDB.DownloadCount++;
_context.SaveChanges();
string downloadName= filesDB.FileDisplayName +
Path.GetExtension(filesDB.FilePath);
return File(filesDB.FilePath, filesDB.FileType, downloadName);
}
答案 0 :(得分:0)
您可以双向下载。只需使用HTML表单即可。
我在这里使用WebService:
<form id="downloadForm" action="MyService.asmx/DownloadFile" method="post" target="_self" >
<input type="hidden" name="id" id="txtID" />
</form>
JS:
function downloadFile() {
$('#txtID').val(id);
$('#downloadForm').submit();
}
只需调用downloadFile(),它将下载并停留在当前页面上。 如果您想以新的方式打开,只需将 target =“ _ self” 更改为 target =“ _ blank”