Link to home
Start Free TrialLog in
Avatar of Eamon
EamonFlag for Ireland

asked on

Open file in new window

I have jquery function which calls an action GetReport which returns a pdf file
This is the Action
 return File(renderedBytes, mimeType);

Open in new window


This is the function
function showReport() {
        var clinic = $("#SelectedClinic").val();
        var date = $("#SelectedDate").val();
      var url = "/Reports/GetReport";
         $.get(url, { SelectedClinic: clinic, SelectedDate: date }, function (data) {
             $("#outPut").html(data);
         });
    }

This is the result
User generated image
I would ideally like to open the pdf file in a new window or tab.
I might also like to show the file DIV $("#outPut") but my real question is how to open it in a new window.


By the way this works
@Html.ActionLink("View in new tab","GetReport","Reports", new {SelectedClinic = "Galway"  }, new { target="_blank" })
but i cannot set the SelectedClinic parameter without doing a post.

The SelectedClinic should come from the dropdown.

Thanks
Eamon
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

You will need to open the new window first and have your script run in that.
Avatar of Eamon

ASKER

$("#outPut").html(data);
in a new window will still not display the report.
But why are you doing it this way

Why not just have

<a href="pathtopdf/file.pdf" _target="blank">Link text</a>

Or

<a href="pathtopdfcontainer.html" _target="blank">Link text</a> and then have the pdf load in this file (or script)?
Avatar of Eamon

ASKER

The action GetReport generates the report and returns a file
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Eamon

ASKER

Thank you
you are welcome - thanks for the points.