MVVM ViewModel 与 MVC ViewModel [英] MVVM ViewModel vs. MVC ViewModel

查看:31
本文介绍了MVVM ViewModel 与 MVC ViewModel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ViewModel 是一个术语,用于 MVVM(模型-视图-视图模型)和 ASP.NET MVC 的推荐实现.鉴于每种模式使用相同的术语,研究ViewModel"可能会令人困惑.

ViewModel is a term that is used in both MVVM (Model-View-ViewModel) and the recommended implementation for ASP.NET MVC. Researching "ViewModel" can be confusing given that each pattern uses the same term.

MVC ViewModel 和 MVVM ViewModel 的主要区别是什么?例如,鉴于缺少控制器,我认为 MVVM ViewModel 更加丰富.这是真的吗?

What are the main differences between the MVC ViewModel and MVVM ViewModel? For example, I believe the MVVM ViewModel is more rich, given the lack of a Controller. Is this true?

推荐答案

一个相当具有挑战性的问题,需要简洁地回答,但我会尝试一下.(请记住,这些问题的答案仍然是开发者之间争论的主题.)

A rather challenging question to answer succinctly, but I'll attempt it. (Bear in mind that the answers to these kinds of questions are still the subject of debate amongst developers.)

在 MVC 中,ViewModel 提供了渲染视图所需的所有信息.它包含的数据是使用模型中定义的数据创建的.View 读取 ViewModel 并呈现输出.来自 View 的输入传递给 Controller,后者操作 Model,构造合适的 ViewModel,并将其传递给 View 进行渲染.

In MVC, the ViewModel provides all the information necessary for a View to be rendered. The data it contains is created using data defined in the Model. The View reads the ViewModel and renders the output. Input from the View is passed to the Controller, which manipulates the Model, constructs an appropriate ViewModel, and passes this to the View for rendering.

在 MVVM 中,ViewModel 的功能与它在 MVC 中的功能相同,但它还通过提供允许 View 操作模型的命令来替换部分 MVC 控制器.WPF 数据绑定根据 ViewModel 的变化管理 View 的更新(这有效地取代了 MVC 控制器的剩余功能).

In MVVM, the ViewModel serves the same function as it does in MVC, but it also replaces part of the MVC Controller by providing commands which allow the View to manipulate the Model. WPF databinding manages the updating of the View according to changes in the ViewModel (and this effectively replaces the remaining function of the MVC Controller).

这篇关于MVVM ViewModel 与 MVC ViewModel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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