Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an MVC.NET C# application. One of the actions returns the File Result
C#
public ActionResult ViewSomePDF()
{
    byte[] fileStream = GetFileStream()
    return File(fileStream, @"application/pdf");
}

The file is being displayed fine; however, I would like to add some HTML controls above the file when it streams. Is that possible in MVC? Can I somehow combine the File Results and the View Result so that the View Result would be on top and the File Result would be on the bottom

Is that possible?

Thank you very much in advance

What I have tried:

I already tried to first call the view and then call the file within the view, but this won't work as I have stream the file for the security purposes
Posted
Updated 9-Feb-22 22:34pm
v2

1 solution

No. If you send a file in the response, you cannot also send HTML.

If you want to display a PDF with some extra controls, you will need two actions: one to return the HTML which displays the controls and loads the PDF, and one to return the PDF.

You'll need to use a Javascript library to display the PDF, since not all browsers can display PDF files inline. For example: mozilla/pdf.js[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900