2016-08-31 57 views
1
window.location = '@Url.Action("PrintReport", "Report")?from=' + $("#fromDate").val() + '&to=' + $("#toDate").val(); 

どうすれば新しいタブで開くことができますか? JavaScriptをクリックして呼び出す。あなたはmvcの新しいタブでウィンドウをJavaScriptで表示

var url = '@Url.Action("PrintReport", "Report")?from=' + 
      $("#fromDate").val() + '&to=' + $("#toDate").val(); 

window.open(url,"_blank") 

以上を持ってクリックした内容に応じ

答えて

2

:ターゲットとのリンク= "_空白" がある -

<a href="#" target="_blank" 
    onclick="this.href='@Url.Action("PrintReport", "Report")?from=' + 
    $("#fromDate").val() + '&to=' + $("#toDate").val();">Print</a> 

それとも控えめ:

を使用して

<a href="#" id="printReport" target="_blank" >Print</a> 

$(function() { 
    $("#printReport").on("click",function(e) { 
    $(this).attr("href",'@Url.Action("PrintReport", "Report")?from=' + 
    $("#fromDate").val() + '&to=' + $("#toDate").val()); 
    }); 
}); 

または両方:

$(function() { 
    $("#printReport").on("click",function(e) { 
    e.preventDefault(); 
    window.open('@Url.Action("PrintReport", "Report")?from=' + 
    $("#fromDate").val() + '&to=' + $("#toDate").val(),"_blank"); 
    }); 
}); 
+1

おかげで、それは完全に私のために動作しています&Iは、多くのことを学びました。 – Metaphor

関連する問題