JS
function DownLoad(path) {
location.href = 'Download?filePath=' + path;
}
controller
public ActionResult Download(string filePath)
{
filePath = filePath.TrimEnd('/').TrimStart('/');
var stream = new WebClient().OpenRead(filePath);
var fileName = System.IO.Path.GetFileName(filePath);
return File(stream, "text/plain", Url.Encode(fileName));
}
本文介绍了一种使用JavaScript在前端触发文件下载的方法,并展示了如何通过C#后端代码提供文件流来响应前端请求。
499

被折叠的 条评论
为什么被折叠?



