Returning a file to View/Download in ASP.NET MVC

前端 未结 9 1596
刺人心
刺人心 2020-11-21 22:41

I\'m encountering a problem sending files stored in a database back to the user in ASP.NET MVC. What I want is a view listing two links, one to view the file and let the mim

9条回答
  •  甜味超标
    2020-11-21 22:49

    Below code worked for me for getting a pdf file from an API service and response it out to the browser - hope it helps;

    public async Task PrintPdfStatements(string fileName)
        {
             var fileContent = await GetFileStreamAsync(fileName);
             var fileContentBytes = ((MemoryStream)fileContent).ToArray();
             return File(fileContentBytes, System.Net.Mime.MediaTypeNames.Application.Pdf);
        }
    

提交回复
热议问题