从控制器的新窗口中打开MVC视图 [英] Open mvc view in new window from controller

查看:146
本文介绍了从控制器的新窗口中打开MVC视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在新窗口中打开从控制器的行动有何看法?

Is there any way to open a view from a controller action in a new window?

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

该如何获得NewWindow.cshtml视图在一个新的浏览器选项卡中打开?

How would I get the NewWindow.cshtml view to open in a new browser tab?

我知道如何从视图中的链接,这样做 - 这不是问题。有没有人想出了一个办法,从的控制器动作的?

I know how to do it from a link in the view - that is not the question. Has anyone figured out a way to do it from the controller action?

推荐答案

这不能从控制器本身中完成的,而是来自你的视图。在我看来,你有两个选择:

This cannot be done from within the controller itself, but rather from your View. As I see it, you have two options:


  1. (使用HTML帮助和直HMTL语法示例)装饰用_blank属性,你的链接

  1. Decorate your link with the "_blank" attribute (examples using HTML helper and straight HMTL syntax)


  • @ Html.ActionLink(LINKTEXT,行动,新{控制器=控制器},{新目标=_空白})

  • < A HREF =@ Url.Action(动作,控制器)目标=_空白>链接文字< / A>

  • @Html.ActionLink("linkText", "Action", new {controller="Controller"}, new {target="_blank"})
  • <a href="@Url.Action("Action", "Controller")" target="_blank">Link Text</a>

使用Javascript功能来打开一个新窗口

Use Javascript to open a new window

window.open(链接URL)

这篇关于从控制器的新窗口中打开MVC视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆