Reputation: 31
in my asp.net mvc project I want an Action Redirect to a url but I want the page to open in new window.
public ActionResult Index(int id)
{
...
return Redirect(page.Url);
}
Upvotes: 1
Views: 4092
Reputation: 557
In the server side you can retrun json (after an ajax call usually)
public ActionResult PreviewReport(Report rep)
{
return Json(new { type = "info", url = "..." }, JsonRequestBehavior.AllowGet);
}
In the client side you execute javascript (the result is from an ajax call to above action)
function (result) {
if (result.type === 'info') {
window.open(result.url, '_blank');
}
}
Upvotes: 1
Reputation: 5605
To open up a new window on client side you will have to do something either in View HTML or use some javascript. This can not be done in controller.
In view, you can set the target property of your action link from where this action is being called.
Upvotes: 3
Reputation: 125538
You should specify that the link will open in a new window using the target
attribute on <a>
element in the view i.e.
<a href="@Url.Action("Index", "Controller", new{ area = "", id = 1 })"
target= "_blank">Link text</a>
Upvotes: 1