DEV Community

Sardar Mudassar Ali Khan
Sardar Mudassar Ali Khan

Posted on

Opening a page in new browser window in asp net mvc application

To open a page in a new browser window in an ASP.NET MVC application, you can use the target attribute of the anchor (<a>) tag. Here's an example:

<a href="@Url.Action("ActionName", "ControllerName")" target="_blank">Open Page</a>
Enter fullscreen mode Exit fullscreen mode

In this example, ActionName and ControllerName should be replaced with the appropriate values for the action method and controller you want to open in the new window.

The target="_blank" attribute tells the browser to open the link in a new window or tab, depending on the user's browser settings.

Alternatively, if you want to open a new window or tab using JavaScript, you can use the window.open() method. Here's an example:

<a href="#" onclick="window.open('@Url.Action("ActionName", "ControllerName")'); return false;">Open Page</a>
Enter fullscreen mode Exit fullscreen mode

In this example, when the link is clicked, the window.open() method is called with the URL generated using @Url.Action(). The return false; statement prevents the default action of the link, which is to navigate to the URL specified in the href attribute. Instead, the window.open() method is invoked, opening the URL in a new window or tab.

Remember to replace ActionName and ControllerName with the appropriate values for your application.

Billboard image

Deploy and scale your apps on AWS and GCP with a world class developer experience

Coherence makes it easy to set up and maintain cloud infrastructure. Harness the extensibility, compliance and cost efficiency of the cloud.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay