1

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);
        }

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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>

2 Comments

Thank you. But In Action I make some controls and decide to open blank target or normal.
You can't set to open in a new window from the server-side, as far as I know.
1

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');
        } 
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.