.net core MVC 下载文件

之前写的下载,在.net core下不能用了,所以重新写了一下。

js代码

function DataExport(URL,data,newName) {
    $.ajax({
        type: 'POST',
        url: URL,
        //contentType: "application/json; charset=utf-8",
        data: data,
        async: false,
        success: function (result) {
            console.log(result);
            setTimeout(function () {
                //异常判断与处理
                if (result.errorCode) {
                    //$.dialog.alert("查询失败。错误码:"+result.errorCode);
                    return;
                }
                console.log(result);

                window.location.href = '/BaseData/Download?fileName=' + result + '&NewName=' + newName

            }, 200);

        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            //$.dialog.alert("查询失败");
            //$wrapper.spinModal(false);
        }
    });
}

controller层代码

        [HttpGet]
        public IActionResult Download(string fileName, string NewName = "")
        {
            var addrUrl = fileName;
            var stream = System.IO.File.OpenRead(addrUrl); //Path.GetExtension
            string fileExt = Path.GetExtension(fileName);
            //获取文件的ContentType
            var provider = new FileExtensionContentTypeProvider();
            var memi = provider.Mappings[fileExt];
           // var downloadName = Path.GetFileName(addrUrl);
            return File(stream, memi, NewName + "Data.xlsx");

           // return File(fileName, "application/vnd.ms-excel", NewName + "Data.xlsx");
        }

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
"Learning ASP.NET Core MVC Programming" English | ISBN: 1786463830 | 2016 | EPUB | 342 pages | 17 MB Key Features Get a first-principles coverage of ASP.NET MVC and the latest release, Core This book is uniquely designed for developers who are looking to transition their skills into the .NET development field The standalone chapter structure leaves you free to explore ASP.NET MVC to immediately solve your pain points Book Description ASP.NET Core MVC helps you build robust web applications using the Model-View-Controller design. This guide will help you in building applications which can be deployed on non-windows platforms such as Linux. In today's age, it is crucial that you possess the ability to separate the programming and business logic, and this is exactly what ASP.NET Core MVC application will help you achieve. This version comes with a number of improvements that enable fast, TDD-friendly development to create sophisticated applications. You would also learn the fundamentals of Entity framework and on how to use the same in ASP.NET Core web applications. The book presents the fundamentals and philosophies of ASP.NET Core. Starting with an overview of the MVC pattern, we quickly dive into the aspects that you need to know to get started with ASP.NET. You will learn about the core architecture of model, view, and control. Integrating your application with Bootstrap, validating user input, interacting with databases, and deploying your application are some of the things that you will be able to execute with this fast-paced guide. The end of the book will test your knowledge as you build a fully working sample application using the skills you've learned throughout the book. What you will learn Get to know the concepts of ASP.NET MVC and build a new static web page using HTML, CSS, and jQuery Set up a development environment and run a sample application using the template Create a Controller with action methods Build a view using several features of the Razor View engine Construct a Model for ASP.NET Core MVC application Devise a custom mechanism to provide maximum flexibility to your application through routing Validate the user input on the client side using jQuery Enhance your applications using Bootstrap Explore new configuration and deployment scenarios—step by step guide to deploying ASP.NET Core web application in Linux
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值