返回JSON并同时重定向到页面或从同一操作返回视图 [英] Return JSON and at the same time redirect to a page or return view from the same action

查看:332
本文介绍了返回JSON并同时重定向到页面或从同一操作返回视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以返回JSON并同时重定向到页面或从视图中通过ajax调用调用的相同操作返回视图。



我尝试过:



返回JSON并同时重定向到页面或从同一个动作返回视图

Is it possible to return JSON and at the same time redirect to a page or return view from the same action invoked through ajax call from view.

What I have tried:

return JSON and at the same time redirect to a page or return view from the same action

推荐答案

请求只能有一个响应,所以如果一个动作返回JSON,它就不能返回任何其他内容。如果您想在json中返回该URL后重定向到一个页面,并且一旦json被处理,您可以读取重定向到的URL。



最终你需要解释你想要达到的目的,看看是否有人有解决方案。
A request can only have one response so if an action returns JSON it can't return anything else. If you want to redirect to a page after you can return that url in the json also and once the json is processed you can read the url to redirect to.

Ultimately you'll need to explain what it is you're trying to achieve to see if someone has the solution.


你可以返回 json 来自操作的数据以及 ajax调用 success 方法中的重定向相关行动

You can return the json data from the action and in the success method of the ajax call just redirect it to relevant action


.ajax({
type: post
dataType: json
url:' controller / action'
数据:{},
成功: function (jsonData){
window location .href = ' @ Url.Action(ActionName,ControllerName)'
}
});
.ajax({ type: "post", dataType: "json", url: 'controller/action', data: { }, success: function (jsonData) { window.location.href = '@Url.Action("ActionName", "ControllerName")' } });


这篇关于返回JSON并同时重定向到页面或从同一操作返回视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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