asp.net-core-mvcactionlink

ASP.NET Core MVC ActionLink arguments


I have a actionlink button (MVC) witch creates an PDF file witch works fine:

@Html.ActionLink("PDF", "CreatePDF", new { id = item.ConnectionID }, new { @class = "btn btn-primary" })

Now I want the button to enforce opening the PDF in a new tab. No problem I thought:

@Html.ActionLink("PDF", "CreatePDF", new { id = item.ConnectionID }, new { @class = "btn btn-primary" }, new { target = "_blank" })

Only, the 'ActionLink' is getting a red squiggly now.

While searching and testing around I noticed that:

@Html.ActionLink("PDF", "CreatePDF", new { id = item.ConnectionID }, new { target = "_blank" })

Works fine on the new tab, except… no button of course.

Seems like the Actionlink doesn’t accept more than two ‘new’ arguments. I tried this as well:

@Html.ActionLink("PDF", "CreatePDF", new { id = item.ConnectionID, target = "_blank" }, new { @class = "btn btn-primary" })

I got rid of the red squiggly, the PDF comes up, but not in an new tab.

Any suggestions?


Solution

  • You nearly got it. The 'target' must be in the 4th argument:

    @Html.ActionLink("PDF", "CreatePDF", new { id = item.ConnectionID}, new { @class = "btn btn-primary", target = "_blank"  })