前端js
window.location.href=“/Message/check_file?filepath=” + 文件路径 + “&name=” +文件名;
ps:/Message/check_file :后台控制器方法名
如果不需要特别写后台下载的方法也可以直接
window.location.href=服务器文件路径;//直接下载
window.open(服务器文件路径);//这样也可以
如果下载时出现连接被重置可能是因为文件的类型被服务器禁止下载了
对应后台方法
public FileResult check_file(string filepath, string name)
{
//本地路径
string ServerFilePath = System.Web.HttpContext.Current.Server.MapPath(filepath);
string s = MimeMapping.GetMimeMapping(name);
return File(ServerFilePath, s, Path.GetFileName(ServerFilePath));
}