0

I've tried the steps outlined in other posts here and here and it just doesn't work. I end up getting redirected to a white screen that just says ... {"redirectTo":"/Administrator/Home"}

C#

    [HttpPost]
    public JsonResult ControllerMethodHere(ViewModel model) {
        // my controller code goes here.
        return Json(new {
            redirectTo = Url.Action("Index", "Home"),
        }, JsonRequestBehavior.AllowGet);
    }

Javascript

    this.save = function () {

            $.ajax({
                url: $('form').attr('action'),
                type: "POST",
                data: ko.toJSON(this),
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                success: function (data) {
                    window.location.href = data.redirectTo;
                }
            });
    };
2
  • If that's what you are seeing, it doesn't seem to me like you're making an XHR request. Have you looked at Firebug/Fiddler to see if you're actually making an XHR request? Commented Jun 2, 2011 at 16:35
  • I don't quite know how to do that, but everything else is working just fine... I mean, it does return the data, it just doesn't read it right. Commented Jun 2, 2011 at 17:11

1 Answer 1

6

Try using this:

window.location = data.redirectTo;
Sign up to request clarification or add additional context in comments.

2 Comments

Yes, this was it. I can't believe it was that simple.
The simple solutions are always the most difficult to track down. Glad it worked out for you!

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.