MVC - 是模型来查看或控制器来查看? [英] MVC - is it model to view or controller to view?

查看:1071
本文介绍了MVC - 是模型来查看或控制器来查看?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到无数的网站和文章解释说,鉴于从像下面的例子中,模型更新 但是我看到显示的视图通过控制器更新MVC架构的其他几个例子

I see numerous sites and articles explaining that the view is updated from the model like the example below however i see a few other examples of MVC architecture showing that the view is updated via the controller

难道这取决于你是否有@Model到您的看法?我只是想知道为什么在不同版本的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.

推荐答案

MVC是一个松散定义的图案,让建筑师太多自由裁量权实施细则。这可能是为什么MVC如此多的变化存在。

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开始了独立的Web应用程序分为三个部分,即模型,视图和控制器。其目标是:

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:

  • 实现模型和视图之间的松耦合(Observer模式 用来实现它)。
  • 在独立的业务逻辑转换模型,以便它可以彻底 测试。
  • 请查看哑/薄越好,以减少需要测试它。
  • Achieve loose coupling between Model and View (Observer pattern employed to achieve it).
  • Separate 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.

的图案迷住了这么多,有几个变化(主动型,被动型,模型2)。这些变化是由于实施模式中的特定框架以适应框架的设计目标。

例如,一种变体是模型2。 Model2的是网页的变化(经典MVC实际上是针对桌面应用程序),并得到了流行的ASP.NET MVC框架。

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".

经典MVC和ASP.NET MVC框架之间的主要区别是,后来提供了一个整洁的分离模型和视图即没有直接的互动之间。而控制器负责,以方便在ASP.NET MVC框架模型和视图之间的通信。这使得ASP.NET MVC框架的Web应用程序有很多简单的&放大器;高效的测试。

The key difference between Classic MVC and ASP.NET MVC Framework is, 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 application a lot easy & efficient to test.

此外,在模型2有一个排序,可以视图和控制器之间建立松散的合同。在ASP.NET MVC框架,该合同重$ P $早些时候ViewData的容器对象psented现在使用视图模型对象是一个天。

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 is represented earlier by the ViewData container object and now a days using a ViewModel object.

要避免混乱,人们需要看这三部分之间的相互作用,在目前使用MVC模式的实现(模型,视图和放大器控制器)。此外拥抱事实,即它是一个特定的实现MVC模式,一个图可能不是最好的来形容了。

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

这篇关于MVC - 是模型来查看或控制器来查看?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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