Eamon
Eamon

Reputation: 3

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);

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 in the

 DIV $("#outPut") 
%PDF-1.3 1 0 obj [/PDF /Text /ImageB /ImageC /ImageI] endobj 5 0 obj << /Length 4660 /Filter /FlateDecode >> stream X ������wॳ ��K����8�Zo�f剥�,9������d�w�К_���ʶ��t��*�������R��z���7k{`[tUٷm���{��ж����� ;��E=�g}7J��.N~��ގ0Xy'o7���.N�[��W�d��Q���1��u:����U��#�����N�V���t~���7ecwd��=fX��i�7�dj;�i��L���

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

Upvotes: 0

Views: 3789

Answers (1)

Ihor Deyneka
Ihor Deyneka

Reputation: 1409

Instead of ajax get you can use standard javascript window.open function.

Here's more information about this: http://www.w3schools.com/jsref/met_win_open.asp

Upvotes: 1

Related Questions