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

前端 未结 10 1696
甜味超标
甜味超标 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 06:03

    With Named arguments:

    @Html.ActionLink(linkText: "TestTab", actionName: "TestAction", controllerName: "TestController", routeValues: null, htmlAttributes: new { target = "_blank"})
    
    0 讨论(0)
  • 2020-12-14 06:03

    asp.net mvc ActionLink new tab with angular parameter

    <a  target="_blank" class="btn" data-ng-href="@Url.Action("RunReport", "Performance")?hotelCode={{hotel.code}}">Select Room</a>
    
    0 讨论(0)
  • 2020-12-14 06:07

    That won't compile since UrlHelper.Action(string,string,object,object) doesn't exist.

    UrlHelper.Action will only generate Urls based on the action you provide, not <a> markup. If you want to add an HtmlAttribute (like target="_blank", to open link in new tab) you can either:

    • Add the target attribute to the <a> element by yourself:

      <a href="@Url.Action("RunReport", "Performance",
          new { reportView = Model.ReportView.ToString() })",
          target = "_blank" type="submit" id="runReport" class="button Secondary">
          @Reports.RunReport
      </a>
      
    • Use Html.ActionLink to generate an <a> markup element:

      @Html.ActionLink("Report View", "RunReport", null, new { target = "_blank" })
      
    0 讨论(0)
  • 2020-12-14 06:12

    For

    @Url.Action

    <a href="@Url.Action("Action", "Controller")" target="_blank">Link Text</a>
    
    0 讨论(0)
提交回复
热议问题