gpt4 book ai didi

asp.net-mvc-4 - 从 Controller 在新窗口中打开 mvc View

转载 作者:行者123 更新时间:2023-12-03 06:01:23 25 4
gpt4 key购买 nike

有什么方法可以在新窗口中从 Controller 操作打开 View 吗?

public ActionResult NewWindow()
{
// some code
return View();
}

如何在新的浏览器选项卡中打开 NewWindow.cshtml View ?

我知道如何从 View 中的链接执行此操作 - 这不是问题。有没有人想出一种方法来通过 Controller 操作来做到这一点?

最佳答案

这不能从 Controller 本身完成,而是从您的 View 完成。在我看来,你有两个选择:

  1. 使用“_blank”属性装饰您的链接(使用 HTML 帮助程序和直接 HMTL 语法的示例)

    • @Html.ActionLink("linkText", "Action", new {controller="Controller"}, new {target="_blank"})
    • <a href="@Url.Action("Action", "Controller")" target="_blank">Link Text</a>
  2. 使用Javascript打开新窗口

    window.open("Link URL")

关于asp.net-mvc-4 - 从 Controller 在新窗口中打开 mvc View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14509616/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com