gpt4 book ai didi

asp.net-mvc - return Json 将在指定 Url 时重定向到另一个 View

转载 作者:行者123 更新时间:2023-12-02 07:31:36 25 4
gpt4 key购买 nike

当您返回 Json(...) 时,您明确告诉 MVC 不要使用 View ,并提供序列化的 JSON 数据。您的浏览器会打开一个下载对话框,因为它不知道如何处理这些数据。

我从下面的链接得到了以上信息

How to return Json object from MVC controller to view

当我在某些操作结果中给出下面的代码时

return Json(new { Url = "sep/employee"}

是否会重定向到指定的 Action ?它如何重定向到 URl ?

对于这种情况,为什么我不能使用 return RedirectToAction("sep/employee")。

返回 Json 代码如何重定向到 Url 中指定的操作。

例如:

public ActionResult Index()
{
................................

return Json(new { Url = "sep/employee"}
}

public ActionResult employee()
{
....................
}

b/s重定向和返回Json有什么区别

最佳答案

您将以下行返回给 ajax success 调用

return Json(new { Url = "sep/employee"});    

然后您需要指定重定向到新页面的位置

success: function(result) {
window.location.href=result.Url;
}

关于asp.net-mvc - return Json 将在指定 Url 时重定向到另一个 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21039680/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com