Is there any way to open a view from a controller action in a new window?
public ActionResult NewWindow()
{
// some code
return View();
}
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:
Decorate your link with the “_blank” attribute (examples using HTML helper and straight HMTL syntax)
@Html.ActionLink("linkText", "Action", new {controller="Controller"}, new {target="_blank"})<a href="@Url.Action("Action", "Controller")" target="_blank">Link Text</a>Use Javascript to open a new window
window.open("Link URL")