MVC3 redirect to url question

I want to call a action in a controller (currently ajax call is there), and once it reaches the action, I need to redirect it to some  other url say www.yahoo.com

so I don't want to return anything to the view but redirect, trying the following:

  public ActionResult ManageActivation(ManageActivationParameters inputs)
        {
                Redirect(string.Format(script));
      }

Open in new window


script is what I am dynamically creating and contains the logic so that url opens in new tab.

how should I call this ManageActivation action from view and what type of modifications I need to make there.
Dinesh KumarAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jens FiedererTest Developer/ValidatorCommented:
If you are doing an AJAX call to the server, the server does not have the power to redirect you.   It COULD return a value to the client which you might evaluate in JavaScript to do a redirect on the client side using Javascript.

You CAN do a redirect if you are doing a full postback.
0
Dinesh KumarAuthor Commented:
how to call the mvc action without using AJAX then and how to redirect to third party url?
0
Jens FiedererTest Developer/ValidatorCommented:
If you are doing something in a context in which a new view would be called up (say in the About action of your Home controller, you can simply do
public ActionResult About()
        {
            return Redirect("http://www.google.com");
        }

Open in new window

to redirect to google.

If you are going to continue using an Ajax call, you want to insert javascript redirect logic in a callback on the client side (in the view) using whatever information your controller sends you.
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

InsoftserviceCommented:
Response.Redirect("http://www.microsoft.com");
0
Dinesh KumarAuthor Commented:
I can open  page in new tab by using following in javascript:
javascript:void window.open ('www.yahoo.com?id=encrypted data', 'window name')

but in case of mvc3, I need to send some data to action which will have some encryption logic on data and then I want to send that data in new page  in new tab.  I don't want to give any data back to the current page that will be same as it was but new tab to be opened.

The above are not working.
0
Dinesh KumarAuthor Commented:
I am not having any control over the new tab page url, only needs to send data to that and opening that in new window.
0
Dinesh KumarAuthor Commented:
Hi Jens,

its working:

public ActionResult About()
        {
            return Redirect("http://www.google.com");
        }


but only thing is to open it in new tab.

I am calling the About() using    location.href
0
Dinesh KumarAuthor Commented:
0
Jens FiedererTest Developer/ValidatorCommented:
If I were doing something like this, I'd probably use an AJAX action and do the work in Javascript.

With the following as an action in the Region controller:
        [HttpPost]
        public ActionResult GetContent(string x)
        {
            return Content("http://www.google.com");
        }

Open in new window


I would use this in the view:
@using (Html.BeginForm())
{
    <button id="ajaxsubmit" type="button">Query</button>
}

<script type="text/javascript">
    $('#ajaxsubmit').click(function () {
        $.ajax({
            url: "Region/GetContent",
            type: "POST",
            data: {x: "data-to-pass"},

            success: function (result) {
                window.open(result, '_blank')
            }
        });
        return false;
    });
</script>

Open in new window


(note that since this uses jQuery you will want to load jquery at the TOP of the layout, not at the bottom)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dinesh KumarAuthor Commented:
Thank you.
0
Jens FiedererTest Developer/ValidatorCommented:
My pleasure
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.