Search code examples
c#pdfdotvvm

How to correctly view pdf in browser using DotVVM?


I'm trying to view PDF in a browser tab using DotVVM.

I've tried to use ReturnFile() method described here https://www.dotvvm.com/docs/tutorials/advanced-returning-files/1-1

with additionalHeaders but it haven't worked.

var additionalHeaders = new List<KeyValuePair<string, string>>
{
    new KeyValuePair<string, string>("Content-Disposition", "inline")
};
using (var file = ...)
{
    Context.ReturnFile(file.Stream, ItemId + "-" + type + ".pdf", "application/pdf", additionalHeaders);
}

Is there any way to view PDF in a browser using ReturnFile() Method or do I have to create my own DotvvMPresenter? Or is there any other suitable way how to manage that?

I've also tried to set up Context.HttpContext.Response.Body/Headers/ContentType , but even that haven't worked.


Solution

  • In DotVVM 2.3.0, we have added an overload ofReturnFile which allows to specify Content-Disposition header. If you set it to inline, it should display the document instead of downloading it.