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?
You can use the RedirectToAction() method, then the action you redirect to can return a View. The easiest way to do this is: return RedirectToAction("Index", model); Then in your Index method, return the view you want.
Call the appropriate /controller/action in your respective button click handlers. In your case for the register button handler direct it to /home/register. Have a view for your register functionality. In the register action of your home controller return the view you want to show.
Create view from controller In MVC 5Open the “HomeController” >> Set cursor inside the Action Method >> Right click on inside the action method >> click on [Add View] as follow. Provide the view name and select the appropriate layout and click on the “Add” button as follows.
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")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With