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.

Top comments (0)