2012-06-01 20 views
44

me tratando de que mi enlace para abrir en una nueva pestaña (que debe estar en formato de afeitar):¿Cómo abrir un enlace de acción de maquinilla en una nueva pestaña?

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

Esto no está funcionando sin embargo. Alguien sabe cómo hacer esto?

+6

¿Por qué te molestaría tratar de poner eso en 'Url.Action'? Solo ingrese la etiqueta ''. –

Respuesta

30

parece que estás confundiendo Html.ActionLink() para Url.Action(). Url.Action no tiene parámetros para establecer el objetivo, ya que solo devuelve una URL.

Sobre la base de su código actual, el ancla probablemente debería verse como:

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

Lo está configurando type como submit. Eso significa que el navegador debe publicar sus datos <form> en el servidor.

De hecho, una etiqueta no tiene ningún tipo de atributo según w3schools.

Tan remoto type atributo y debería funcionar para usted.

+1

No pondría mucha confianza en [w3fools] (http://w3fools.com/) – dtsg

+1

seguro, todos debemos confiar en IE :) – Sly

94

Simplemente use HtmlHelperActionLink y configure RouteValues y HtmlAttributes en consecuencia.

@Html.ActionLink(Reports.RunReport, "RunReport", new { controller = "Performance", reportView = Model.ReportView.ToString() }, new { target = "_blank" }) 
+1

Este es el enfoque recomendado si el enlace es solo de texto. –

16

que no va a compilar desde UrlHelper.Action(string,string,object,object) no existe.

UrlHelper.Action solo generará Urls en función de la acción que proporcione, no del marcado <a>. Si desea agregar un HtmlAttribute (como target="_blank", para abrir enlace en una nueva pestaña) puede:

  • Añadir el atributo de destino al elemento <a> en solitario:

    <a href="@Url.Action("RunReport", "Performance", 
        new { reportView = Model.ReportView.ToString() })", 
        target = "_blank" type="submit" id="runReport" class="button Secondary"> 
        @Reports.RunReport 
    </a> 
    
  • usar HTML .ActionLink para generar un elemento <a> marcado:

    @Html.ActionLink("Report View", "RunReport", null, new { target = "_blank" }) 
    
+2

Esta debería ser la respuesta aceptada – sveilleux2

0

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

14

Si su objetivo es utilizar el ayudante ActionLink y abrir una nueva pestaña:

@Html.ActionLink("New tab please", "Home", null , new { target = "_blank" }) 

@Html.ActionLink("New tab please", "Home", Nothing, New With {Key .target = "_blank"}) 
2

Con Los argumentos con nombre:

@Html.ActionLink(linkText: "TestTab", actionName: "TestAction", controllerName: "TestController", routeValues: null, htmlAttributes: new { target = "_blank"}) 
1

asp.net mvc ActionLink nueva pestaña con el parámetro angular

<a target="_blank" class="btn" data-ng-href="@Url.Action("RunReport", "Performance")?hotelCode={{hotel.code}}">Select Room</a> 
Cuestiones relacionadas