发送请求,让服务器的某个文件下载

Js:发送请求:

window.location.href = "/Log/DownloadExcel?Excel=" + data;

Controller:

public ActionResult DownloadExcel()
        {
            string excel = Request.QueryString["Excel"] ?? "";
            //if (excel == "")
            //{
            //    return;
            //}
            string path = System.Web.HttpContext.Current.Server.MapPath("~/Excel");
            string filepath = string.Format("{0}\{1}", path, excel);
            string name = Path.GetFileName(filepath);
            return File(filepath, "application/x-zip-compressed", name);
        }
原文地址:https://www.cnblogs.com/zychengzhiit1/p/4736197.html