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;
                }
            });
    };
Community
  • 1
  • 1
Ciel
  • 17,312
  • 21
  • 104
  • 199
  • 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? – ek_ny Jun 02 '11 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. – Ciel Jun 02 '11 at 17:11

1 Answers1

6

Try using this:

window.location = data.redirectTo;
Paul
  • 12,392
  • 4
  • 48
  • 58