使用asp.net mvc的文件下载 [英] File Download using asp.net mvc

查看:156
本文介绍了使用asp.net mvc的文件下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着用下面的code。但它并没有正常工作。

 公共FileResult下载(字符串路径)
{
   返回文件(路径,应用程序/ PDF,Server.UrlEn code(路径));
}

我的阿贾克斯code是:

 函数fileDownload(路径){
    $阿贾克斯({
       网址:'/主页/下载',
       数据:{路径:路径},
       输入:POST,
       异步:假的,
       成功:功能(数据){}
    });
}


解决方案

这个任务使用window.location的方法完成

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

这篇关于使用asp.net mvc的文件下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆