【发布时间】:2011-06-02 16:30:30
【问题描述】:
我已经尝试过其他帖子here 中列出的步骤
和here,它只是不起作用。我最终被重定向到一个白屏,上面写着...... {"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;
}
});
};
【问题讨论】:
-
如果这就是您所看到的,在我看来,您似乎不是在发出 XHR 请求。您是否查看过 Firebug/Fiddler 以了解您是否真的在发出 XHR 请求?
-
我不太清楚该怎么做,但其他一切都很好......我的意思是,它确实返回了数据,只是读取不正确。
标签: json asp.net-mvc-3 redirect routing