[英]MVC architecture control flow
I am a bit confused how the three components - Model, View, Controller - interact with each other in MVC architecture. 我有点困惑,这三个组件-模型,视图,控制器-在MVC体系结构中如何相互影响。 Sometimes I feel I know how MVC works and sometimes I feel I don't know its inner working properly.
有时我感觉我知道MVC的工作原理,有时我感觉我不知道它的内部工作正常。
What I know about MVC architecture is - 我对MVC架构的了解是-
Here in my opinion, View never talks to the Model directly. 在我看来,View从不直接与模型对话。 The interaction between the View and Model will be handled by the Controller only .
视图和模型之间的交互将仅由Controller处理。
So far so good! 到现在为止还挺好!
But when I see diagrams like below then I get confused. 但是当我看到如下图时,我会感到困惑。 In the below diagram, the left arrow shows that View component can also interact with the Model component.
在下图中,左箭头表示View组件也可以与Model组件进行交互。
Also in this code-project article, it is written that "A model is accessible by both controller and view" and "a view can use model to display data". 同样在此代码项目文章中,还写道:“控制器和视图都可以访问模型”和“视图可以使用模型显示数据”。
So kindly clarify whether a model is accessible only by the controller or by both the controller and the view. 因此,请澄清是仅控制器可以访问模型还是控制器和视图都可以访问模型。 And if second one is also correct then in what situation this is possible.
如果第二个也是正确的,那么在什么情况下这是可能的。 I work on ASP.NET MVC Framework and here any interaction is done through a controller object.
我使用ASP.NET MVC Framework,在这里任何交互都是通过控制器对象完成的。 I have never encountered a situation where a view directly talks to the model object.
我从未遇到视图直接与模型对象对话的情况。
There's MVC, the pattern, and MVC, the web application framework developed by Microsoft and confusingly named after the pattern, so it's best to break those two out and discuss separately. 有MVC(该模式)和MVC(由Microsoft开发并以该模式混乱地命名)的Web应用程序框架,因此最好将两者分开讨论。
In MVC, the pattern, you'll find the following: 在MVC模式中,您将找到以下内容:
In MVC, the web application framework: 在MVC中,Web应用程序框架:
Despite the name, the MVC framework only loosely implements the MVC pattern. 尽管名称如此,MVC框架仅松散地实现了MVC模式。 However, in both, the Model is accessible by both the controller and the view, so your fundamental understanding there is flawed.
但是,在这两种模型中,控制器和视图都可以访问模型,因此您对模型的基本理解存在缺陷。 In the case of the MVC framework, though, you could say that only the view model is accessible to the view.
但是,对于MVC框架,您可以说视图只能访问视图模型。 Since the "Model" in the MVC framework is not just one thing, there are constituent parts that should not be accessible by the view, namely: the DAL layer and potentially the entity, unless the entity is doing double duty as the view model, as well.
由于MVC框架中的“模型”不仅仅是一件事,因此视图不应访问某些组成部分,即:DAL层和潜在的实体,除非实体作为视图模型承担双重责任,也一样
In Case If the view is Strongly typed with any models then we can say 如果视图是任何模型的强类型输入,那么我们可以说
View=> models 查看=>模型
In Case if view is not strongly typed with models then we can say 如果视图不是用模型强类型化的,那么我们可以说
controller=>Models=> Views 控制器=>模型=>视图
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.