How to have a a razor action link open in a new tab?

前端 未结 10 1695
甜味超标
甜味超标 2020-12-14 05:41

I trying to get my link to open in a new tab (it must be in razor format):

    

        
相关标签:
10条回答
  • 2020-12-14 05:47

    If your goal is to use the ActionLink helper and open a new tab:

    @Html.ActionLink("New tab please", "Home", null , new { target = "_blank" })
    
    @Html.ActionLink("New tab please", "Home", Nothing, New With {Key .target = "_blank"})
    
    0 讨论(0)
  • 2020-12-14 05:47

    <a href="@Url.Action("RunReport", "Performance", new { reportView = Model.ReportView.ToString() })" type="submit" id="runReport" target="_blank" class="button Secondary"> @Reports.RunReport </a>

    0 讨论(0)
  • 2020-12-14 05:49

    Looks like you are confusing Html.ActionLink() for Url.Action(). Url.Action has no parameters to set the Target, because it only returns a URL.

    Based on your current code, the anchor should probably look like:

    <a href="@Url.Action("RunReport", "Performance", new { reportView = Model.ReportView.ToString() })" 
       type="submit" 
       id="runReport" 
       target="_blank"
       class="button Secondary">
         @Reports.RunReport
    </a>
    
    0 讨论(0)
  • 2020-12-14 05:54

    Just use the HtmlHelper ActionLink and set the RouteValues and HtmlAttributes accordingly.

    @Html.ActionLink(Reports.RunReport, "RunReport", new { controller = "Performance", reportView = Model.ReportView.ToString() }, new { target = "_blank" })
    
    0 讨论(0)
  • 2020-12-14 05:56
    @Html.ActionLink(
    "Pay Now",
    "Add",
    "Payment",
    new { @id = 1 },htmlAttributes:new { @class="btn btn-success",@target= "_blank" } )
    
    0 讨论(0)
  • 2020-12-14 05:57

    You are setting it't type as submit. That means that browser should post your <form> data to the server.

    In fact a tag has no type attribute according to w3schools.

    So remote type attribute and it should work for you.

    0 讨论(0)
提交回复
热议问题