I want to upload a pdf file to the page. To load created in the controller the following method

public FileContentResult Read(int bookId) { Book book = context.Books.FirstOrDefault(b => b.Id == bookId); string path = Server.MapPath($"~/Content/Books/{book.GeneratedName}");//Путь к файлу string type = $"application/{GetType(book.GeneratedName)}";//Тип файла byte[] fileContents = System.IO.File.ReadAllBytes(path);//Получение файла в байтовом виде return new FileContentResult(fileContents, type); } 

View code that calls this method and generates content.

  <p>@{Html.RenderAction("Read",new { bookId = Model.Id });}</p> 

But, when accessing this page, an exception is generated.

 System.Web.HttpException: При использовании особого объекта TextWriter свойство OutputStream недоступно. 
  • Are you sure about RenderAction? You have the same file. - VladD
  • Here, it seems, the same problem: stackoverflow.com/q/2776880/276994 - VladD
  • @VladD Exception comes from System.IO, it has nothing to do with FileContentResult - Divannaya Analitik
  • Why do you think that is not related? Have you tried what is described in that question? Who throws an exception is not necessarily the one to blame. - VladD
  • @VladD Yes, I experimented several times and realized that the exception comes from the System.IO classes. And I also realized that with FileContentResult I would not be able to upload content to a part of the page, it still redirects to a separate page - Divannaya Analitik

0