Open a PDF in new tab from URL from my MVC Controller [EDITED]

Dan B

In my view, I generate a link with a username, acct number and date that is passed to the controller:

   @Html.ActionLink(AccountGroup.AcctNum + " " + AccountGroup.DocDate.ToShortDateString(), "GetIndividualStatement", "Statements",  new { statementDate = @AccountGroup.DocDate.ToShortDateString(), Userid = @ViewBag.UserID, acctNumber = AccountGroup.AcctNum.ToString() }, new { @class = "form-control, col-sm-6,  medwidth" , target = "_blank" })

I have tried to use an AJAX link also:

 @Ajax.ActionLink(AccountGroup.AcctNum + " " + AccountGroup.DocDate.ToShortDateString(), "GetIndividualStatement", "Statements", new { statementDate = @AccountGroup.DocDate.ToShortDateString(), Userid = @ViewBag.UserID, acctNumber = AccountGroup.AcctNum.ToString() }, new AjaxOptions { HttpMethod ="POST", UpdateTargetId = "detailsDiv" }, new { @class = "form-control, col-sm-6,  medwidth" })

Then my controller takes that info generates an encrypted URL for the PDF (I have to create this on the spot in my controller, so I cannot just have a link in my view for the user to click (that would be too easy!). I need to open the URL which returns a PDF. I need to take that and open that PDF in a new tab (while keeping the original tab open). Here is my latest attempt, which opens in the same window, but how do I open in a new tab ?

    WebClient client = new WebClient();
    Byte[] buffer = client.DownloadData(path);
    if (buffer != null)
    {
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-length", buffer.Length.ToString());
        Response.BinaryWrite(buffer);
    }

Thanks to all!

Vanquished Wombat

What you are looking for in the final HTML that you produce is something of the form below, where the link has the target attribute set to '_blank',

<a href="the_pdf_link/" target="_blank">Open PDF</a> 

Get that right and you will get the behaviour you want.

If the issue is in the server-side code then when you solve it, edit your question to include the fix just so anyone else looking in from the future can see both sides of the story.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Joomla - Is it possible to open link in new tab from controller

From Dev

How to make PDF from GitHub open in new tab?

From Dev

How to make PDF from GitHub open in new tab?

From Dev

Open URL in new tab from IPython Notebook/Jupyter cell

From Dev

How to open url in new tab from JavaScript script

From Dev

How to open the previous url from the history in a new tab in Vimperator

From Dev

Open a view programmatically with tab controller from storyboard

From Dev

ASP.NET MVC - Conditionally open PDF/Image on new Tab

From Dev

How to open page in new tab from GridView?

From Dev

How to open a terminal in new tab from VIM?

From Dev

Open URLs in a new tab from command line

From Dev

How open the new tab from IE

From Dev

How to open page in new tab from GridView?

From Dev

Read a URL from a file and open it in a Firefox tab

From Dev

Open PDF in a new tab in browser

From Dev

Prevent Chrome for iOS from opening "Open in New Tab .. Copy Link URL" pop-up

From Dev

How to open a database stored URL from Reporting Services Report in a new tab

From Dev

How to pass additional parameters but not in url when hitting mvc controller from javascript window open

From Dev

Force a URL to open in a new tab

From Dev

Conditionally open url in new tab

From Dev

Force a URL to open in a new tab

From Dev

How do I add a link to open a pdf file in a new window from my R shiny app?

From Dev

ios: How open Tab Bar controller from ViewController using StoryBoards

From Dev

Open new tab in ember controller function

From Java

Open a URL in a new tab (and not a new window)

From Dev

EmberJS: Get PDF in a new window tab from server using link

From Dev

R shiny open the URLs from renderTable in a new tab

From Dev

Button link open in a new tab with link from database

From Dev

Open new tab from asp button's codebehind

Related Related

  1. 1

    Joomla - Is it possible to open link in new tab from controller

  2. 2

    How to make PDF from GitHub open in new tab?

  3. 3

    How to make PDF from GitHub open in new tab?

  4. 4

    Open URL in new tab from IPython Notebook/Jupyter cell

  5. 5

    How to open url in new tab from JavaScript script

  6. 6

    How to open the previous url from the history in a new tab in Vimperator

  7. 7

    Open a view programmatically with tab controller from storyboard

  8. 8

    ASP.NET MVC - Conditionally open PDF/Image on new Tab

  9. 9

    How to open page in new tab from GridView?

  10. 10

    How to open a terminal in new tab from VIM?

  11. 11

    Open URLs in a new tab from command line

  12. 12

    How open the new tab from IE

  13. 13

    How to open page in new tab from GridView?

  14. 14

    Read a URL from a file and open it in a Firefox tab

  15. 15

    Open PDF in a new tab in browser

  16. 16

    Prevent Chrome for iOS from opening "Open in New Tab .. Copy Link URL" pop-up

  17. 17

    How to open a database stored URL from Reporting Services Report in a new tab

  18. 18

    How to pass additional parameters but not in url when hitting mvc controller from javascript window open

  19. 19

    Force a URL to open in a new tab

  20. 20

    Conditionally open url in new tab

  21. 21

    Force a URL to open in a new tab

  22. 22

    How do I add a link to open a pdf file in a new window from my R shiny app?

  23. 23

    ios: How open Tab Bar controller from ViewController using StoryBoards

  24. 24

    Open new tab in ember controller function

  25. 25

    Open a URL in a new tab (and not a new window)

  26. 26

    EmberJS: Get PDF in a new window tab from server using link

  27. 27

    R shiny open the URLs from renderTable in a new tab

  28. 28

    Button link open in a new tab with link from database

  29. 29

    Open new tab from asp button's codebehind

HotTag

Archive