MVC下载文件

public ActionResult DownLoad() { var download = new Download(); using (DataClasses1DataContext db = new DataClasses1DataContext()) { download = db.Download.FirstOrDefault(); } string fileName = !String.IsNullOrWhiteSpace(download.Filename) ? download.Filename : "TestFile"; string contentType = !String.IsNullOrWhiteSpace(download.ContentType) ? download.ContentType : "application/octet-stream"; return new FileContentResult(download.DownloadBinary.ToArray(), contentType) { FileDownloadName = fileName + download.Extension }; }
原文地址:https://www.cnblogs.com/opts/p/7872308.html