文件下载使用asp.net mvc [英] File Download using asp.net mvc
本文介绍了文件下载使用asp.net mvc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用以下代码。但是它没有起作用。
public FileResult下载(string path)
{
return File ,application / pdf,Server.UrlEncode(path));
}
我的Ajax代码是:
$ b数据:{路径:路径},
类型:'POST',
async:false,
成功:function(data){}
});
}
解决方案
另外您可以使用HTML标签:
< a href =Pathdownload =Filename>下载我< / a>
I tried using the below code. But it did not work.
public FileResult download(string path)
{
return File(path, "application/pdf", Server.UrlEncode(path));
}
My Ajax Code is:
function fileDownload(path) {
$.ajax({
url: '/Home/download',
data: { path: path },
type: 'POST',
async: false,
success: function (data) { }
});
}
解决方案
This task is complete using window.location method.
Also You can use HTML tag for this:
<a href="Path" download="Filename">download me</a>
这篇关于文件下载使用asp.net mvc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文