[英]open a new tab using MVC Razor @Url.Action
Am trying to work out how to open a tab when i click a link. 我正在尝试找出如何在单击链接时打开选项卡。
Here is my link which am trying to open, i have set it as this, but as you can see i have added target = "_blank" which does not open in a new tab. 这是我要打开的链接,我已将其设置为此,但是如您所见,我添加了target =“ _blank”,它不会在新选项卡中打开。
<div data-callno='@parts.Call_Num' data-url="@Url.Action("GetCallInfo", "CallHandling" , new {target = "_blank"})">
<div class="callViewSubmit toolbarIcon"></div>
Test </div>
This opens on the same page, after looking at google i noticed am using URL.ACTION and not HTML.ACTIONLINK. 这在同一页上打开,在查看Google后,我注意到我正在使用URL.ACTION而不是HTML.ACTIONLINK。
as a test i tried this on the page, and it did open in a new tab: 作为测试,我在页面上尝试了此操作,它确实在新标签页中打开:
@Html.ActionLink("New report", "New", "Report", null, new {target = "_blank"})
Any ideas how i can open my div in a new tab using the Url.Action way. 任何有关如何使用Url.Action方式在新标签页中打开div的想法。
//New //新
This is the javascript i used to open the link, would i able to open the link in javascript rather than url.action 这是我用来打开链接的javascript,我能用javascript而不是url.action打开链接
$(document).ready(function () {
$('.callViewSubmit').click(function () {
$.ajax({
type: "GET",
url: $(this).parent().data("url"),
data: { callNumber: $(this).parent().data("callno") },
success: function (data) {
$("#CallDetail").html(data);
},
});
});
});
如果您要在data-*
属性中分配此属性(并且唯一可以修改的就是URI,则您无能为力,无法完成该行为。这需要在访问data-url
的代码段中进行更改(并且如何处理)。
If you are needing to open the URL in a new tab/window, then AJAX is not the correct way to go. 如果您需要在新标签页/窗口中打开URL,则AJAX不是正确的方法。 You can still open a new tab/window from javascript. 您仍然可以通过javascript打开新的标签/窗口。
$(document).ready(function () {
$('.callViewSubmit').click(function () {
window.open($(this).parent().data("url"));
});
});
You can use this way: 您可以使用这种方式:
Url.RouteUrl("routeName",
new
{
controller = "controllerName",
action = "ActionName",
callNumber: "Value"
});
Then create link: 然后创建链接:
var link =
"<a data-original-title=\"title\" target='_top' data-toggle=\"tooltip\" data-placement=\"top\" " +
"href=\"" + viewLink +
"\" data-ajax=\"true\" data-ajax-method=\"GET\" data-ajax-mode=\"replace\" " +
"data-ajax-update=\"#CallDetail\" >" + This is link;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.