指定网址时,返回Json将重定向到另一个视图 [英] return Json will redirects to another view when Url specified

查看:129
本文介绍了指定网址时,返回Json将重定向到另一个视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

When you do return Json(...) you are specifically telling MVC not to use a view, and to serve serialized JSON data. Your browser opens a download dialog because it doesn't know what to do with this data.

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

i got the above information from below link

如何将Json对象从MVC控制器返回到查看

当我在某些操作结果中提供以下代码时

when i give this below code in some action result

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

它是否将重定向到指定的操作?它如何重定向到URl?

whether it will redirect to specified action ? how it redirects to the URl ?

在这种情况下,为什么我不能使用return RedirectToAction("sep/employee").

for this case why i cant use return RedirectToAction("sep/employee").

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

how return Json code redirects to action which specified in the Url.

例如:

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

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

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

b/s redirectaction和返回Json有什么区别

what is the difference b/s redirectaction and return Json

推荐答案

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

You return the following line to an ajax success call

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

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

you then need to specify where to redirect to the new page

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

这篇关于指定网址时,返回Json将重定向到另一个视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆