How can I combine View Result and File Results in MVC.NET

Mikhail 41 Reputation points
2022-02-09T19:42:14.707+00:00

I have an MVC.NET C# application. One of the actions returns the File Result

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

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,231 questions
{count} votes

Accepted answer
  1. AgaveJoe 26,021 Reputation points
    2022-02-10T11:55:02.663+00:00

    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?

    This is not possible in any browser based application. The browser can either download a file or refresh the page with HTML not both. As YijingSun-MSFT suggested, return a View. The View contains a simple JavaScript application to download the file.

    https://stackoverflow.com/questions/3749231/download-file-using-javascript-jquery

    0 comments No comments

0 additional answers

Sort by: Most helpful