你的位置:首页 > ASP.net教程

[ASP.net教程]发送请求,让服务器的某个文件下载


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);    }