重定向应该在哪里进行 [英] Where should redirects be done

查看:86
本文介绍了重定向应该在哪里进行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在互联网上进行了一些搜索,以寻找可能是一个简单的问题.当使用MVC风格的编程时,应该在哪里执行HTTP重定向?有人说这是控制器层的工作,而有人说这是视图层的工作.

I have searched a little around the internet looking for what might be a simple question. When using the MVC style of programming, where should a HTTP redirect be performed? Some say its a job for the controller layer and others say it is a job for the view layer.

根据我目前对MVC的理解,它将是协调业务逻辑的控制器.但是我理解那些声称这将是视图层的人的说法,即重定向会更改客户端将收到的视觉呈现.

From my current understanding of MVC it would be the controller as it coordinates the business logic. But I understand those who claim it would be the view layer with the argument that a redirect changes the visual presentation a client would receive.

任何人都可以对此有所了解吗?

Can anyone shed some light on this?

推荐答案

MVC结构中的视图负责产生对用户活动的响应. HTTP Location标头将是该响应的一部分.

Views in MVC structure is responsible for producing the response to user's activities. HTTP Location header would be part of that response.

此外,控制器不负责处理业务逻辑.业务逻辑包含在模型层中.相反,控制器负责更改模式层的状态.

Also, controllers are not responsible for dealing with business logic. The business logic is contained in the model layer. The controllers instead are in charge of altering the state of mode layer.

这篇关于重定向应该在哪里进行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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