MVVM视图模型与MVC视图模型 [英] MVVM ViewModel vs. MVC ViewModel

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

问题描述

视图模型是在两个MVVM(模型 - 视图 - 视图模型)中的术语和ASP.NET MVC的建议执行。研究可以是混乱给视图模型,每个模式使用相同的期限。

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视图模型和视图模型MVVM之间的主要区别?例如,我相信MVVM视图模型更加丰富,由于缺乏一个控制器。这是真的吗?

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中,视图模型提供所需的所有信息,被渲染视图。它包含的数据是使用模型中定义的数据创建的。视图读取视图模型并呈现输出。从视图的输入被传递到控制器,该操纵模型,构建一个适当的视图模型,并将该向视图呈现

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,视图模型具有相同的作用,因为它在MVC中那样,但它也可以通过提供其允许查看操纵模型命令替换了MVC控制器的一部分。 WPF数据绑定根据视图模型的变化管理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视图模型与MVC视图模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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