来自MVC控制器的JSON重定向无法正常工作

时间:2011-06-02 16:30:31

标签: json asp.net-mvc-3 redirect routing

我已尝试过其他帖子here中列出的步骤 和here它只是不起作用。我最终被重定向到一个只是说...... {"redirectTo":"/Administrator/Home"}

的白色屏幕

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

1 个答案:

答案 0 :(得分:6)

尝试使用:

window.location = data.redirectTo;