In this article I will explain with an example, how to open Page (View) in New Tab (Window) on
Button Click in
ASP.Net MVC Razor.
Button cannot be used to open Page (View) in New Tab (Window) and hence using
JavaScript’s window.open function, the Page (View) will be opened in New Tab (Window) on
Button Click in
ASP.Net MVC Razor.
Controller
The Controller consists of following Action methods.
Action method for handling GET operation for Index
Inside this Action method, simply the View is returned.
Action method for handling GET operation for About
Inside this Action method, simply the View is returned.
public class HomeController : Controller
{
// GET: Home
public ActionResult Index()
{
return View();
}
public ActionResult About()
{
return View();
}
}
View
HTML Markup
The View consists of an
HTML Button assigned with an
OnClick event handler.
When the
Button is clicked, the About View is opened in New Tab (Window) using
window.open function of
JavaScript.
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<input type="button" value="Open" onclick="window.open('@Url.Action("About", "Home")')" />
</body>
</html>
Screenshot
Browser Compatibility
* All browser logos displayed above are property of their respective owners.
Downloads