user956661
user956661

Reputation: 31

Asp.net Mvc Redirect Url

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

Answers (3)

alexqc
alexqc

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

Maheep
Maheep

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

Russ Cam
Russ Cam

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

Related Questions