MVC—视图或控制器视图的模型?

时间:2022-10-22 11:25:02

I see numerous sites and articles explaining that the view is updated from the model like the example below MVC—视图或控制器视图的模型? however i see a few other examples of MVC architecture showing that the view is updated via the controller MVC—视图或控制器视图的模型?

我看到很多网站和文章解释说视图是从模型中更新的,比如下面的例子,但是我看到一些MVC架构的其他例子表明视图是通过控制器更新的

Is this depending on whether you have the @Model into your views? im just wondering why the different versions of MVC, we were taught that it should be the second image.

这是否取决于您的视图中是否有@Model ?我只是想知道为什么不同版本的MVC,我们被告知它应该是第二个映像。

1 个解决方案

#1


9  

MVC is a loosely defined pattern that gives the architect much discretion over implementation details. This is probably why so many variations of MVC exist.

MVC是一个松散定义的模式,它使架构师在实现细节上有很大的*裁量权。这可能就是为什么有这么多MVC变体存在的原因。

To my knowledge, it all started with Classic (Original) MVC that separate web application into three parts i.e. Model, View and Controller. The objectives were:

据我所知,这一切都始于经典的(原始的)MVC,它将web应用程序分为三个部分,即模型、视图和控制器。目标是:

  • Achieve loose coupling between Model and View (Observer pattern employed to achieve it).
  • 实现模型和视图之间的松散耦合(使用观察者模式实现)。
  • Encapsulate business logic into Model so that it can be exhaustively tested.
  • 将业务逻辑封装到模型中,以便对其进行彻底的测试。
  • Make View as dumb/thin as possible to lessen the need to test it.
  • 尽可能地让视图保持哑/瘦,以减少测试的需要。

MVC—视图或控制器视图的模型?

The pattern charmed so many that there were several variations (Active Model, Passive Model, Model2). These variations were due to implementations of the pattern in particular frameworks to suit the frameworks' design goals.

这种模式吸引了如此多的人,以至于出现了多种变化(主动模型、被动模型、模型2)。这些变化是由于模式在特定框架中的实现以适应框架的设计目标。

For example, one variation is Model2. Model2 is a web variation (Classic MVC was actually targeted for desktop application) and got popular as "ASP.NET MVC Framework".

例如,一个变体是模型2。Model2是一个web变体(Classic MVC实际上是针对桌面应用程序的),并被称为“ASP”。净MVC框架”。

MVC—视图或控制器视图的模型?

The key difference between Classic MVC and ASP.NET MVC Framework is, the later provides a neat separation between Model and View i.e. no direct interaction. Rather Controller is responsible to facilitate this communication between Model and View in ASP.NET MVC Framework. This makes ASP.NET MVC Framework web applications a lot easier & efficient to test.

经典MVC和ASP之间的关键区别。NET MVC框架是,后者提供了模型和视图之间的简洁分离,即没有直接的交互。相反,控制器负责在ASP中促进模型和视图之间的通信。净MVC框架。这使得ASP。NET MVC框架web应用程序测试起来更加容易和高效。

Furthermore, in Model2 there's a sort of loose contract that can be established between the view and the controller. In the ASP.NET MVC Framework, this contract used to be represented by the ViewData container object and nowadays using a ViewModel object.

此外,在Model2中,视图和控制器之间可以建立一种松散的契约。在ASP。NET MVC框架,这个契约以前由ViewData容器对象表示,现在使用ViewModel对象。

To avoid confusion, one need to look at the interactions between these three parts (Model, View & Controller) in the MVC pattern implementations currently in use. Also embrace the fact that it is a particular implementation of MVC pattern and one diagram may not be able to describe it completely.

为了避免混淆,需要查看当前使用的MVC模式实现中这三个部分(模型、视图和控制器)之间的交互。另外,它是MVC模式的一个特殊实现,一个图可能不能完整地描述它。

#1


9  

MVC is a loosely defined pattern that gives the architect much discretion over implementation details. This is probably why so many variations of MVC exist.

MVC是一个松散定义的模式,它使架构师在实现细节上有很大的*裁量权。这可能就是为什么有这么多MVC变体存在的原因。

To my knowledge, it all started with Classic (Original) MVC that separate web application into three parts i.e. Model, View and Controller. The objectives were:

据我所知,这一切都始于经典的(原始的)MVC,它将web应用程序分为三个部分,即模型、视图和控制器。目标是:

  • Achieve loose coupling between Model and View (Observer pattern employed to achieve it).
  • 实现模型和视图之间的松散耦合(使用观察者模式实现)。
  • Encapsulate business logic into Model so that it can be exhaustively tested.
  • 将业务逻辑封装到模型中,以便对其进行彻底的测试。
  • Make View as dumb/thin as possible to lessen the need to test it.
  • 尽可能地让视图保持哑/瘦,以减少测试的需要。

MVC—视图或控制器视图的模型?

The pattern charmed so many that there were several variations (Active Model, Passive Model, Model2). These variations were due to implementations of the pattern in particular frameworks to suit the frameworks' design goals.

这种模式吸引了如此多的人,以至于出现了多种变化(主动模型、被动模型、模型2)。这些变化是由于模式在特定框架中的实现以适应框架的设计目标。

For example, one variation is Model2. Model2 is a web variation (Classic MVC was actually targeted for desktop application) and got popular as "ASP.NET MVC Framework".

例如,一个变体是模型2。Model2是一个web变体(Classic MVC实际上是针对桌面应用程序的),并被称为“ASP”。净MVC框架”。

MVC—视图或控制器视图的模型?

The key difference between Classic MVC and ASP.NET MVC Framework is, the later provides a neat separation between Model and View i.e. no direct interaction. Rather Controller is responsible to facilitate this communication between Model and View in ASP.NET MVC Framework. This makes ASP.NET MVC Framework web applications a lot easier & efficient to test.

经典MVC和ASP之间的关键区别。NET MVC框架是,后者提供了模型和视图之间的简洁分离,即没有直接的交互。相反,控制器负责在ASP中促进模型和视图之间的通信。净MVC框架。这使得ASP。NET MVC框架web应用程序测试起来更加容易和高效。

Furthermore, in Model2 there's a sort of loose contract that can be established between the view and the controller. In the ASP.NET MVC Framework, this contract used to be represented by the ViewData container object and nowadays using a ViewModel object.

此外,在Model2中,视图和控制器之间可以建立一种松散的契约。在ASP。NET MVC框架,这个契约以前由ViewData容器对象表示,现在使用ViewModel对象。

To avoid confusion, one need to look at the interactions between these three parts (Model, View & Controller) in the MVC pattern implementations currently in use. Also embrace the fact that it is a particular implementation of MVC pattern and one diagram may not be able to describe it completely.

为了避免混淆,需要查看当前使用的MVC模式实现中这三个部分(模型、视图和控制器)之间的交互。另外,它是MVC模式的一个特殊实现,一个图可能不能完整地描述它。