1.将需要下载的文档添加到项目的文件夹中
2.接口部分
public IActionResult DownLoad() { var filePath = Directory.GetCurrentDirectory() + "\\UploadFileTemplate"; var strFileName = "Manual courier dispatch record upload.xlsx"; var strPath = filePath + @"\\" + strFileName; var stream = System.IO.File.OpenRead(strPath); return File(stream, "Application/x-msexcel", strFileName); }
3.前端部分
$("#Download").click(function () { window.location.href =' @Url.Action("DownLoad", "MR")'; });