ASP.NET MVC 模型与 ViewModel [英] ASP.NET MVC Model vs ViewModel

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

问题描述

好的,我一直在听到有关 MS 的 ASP.NET MVC 的ViewModels"的讨论.

OK, I have been hearing discussion about "ViewModels" in regards to MS's ASP.NET MVC.

现在,这是一种特定类型的模型,对吗?不是特定类型的视图.

Now, that is intended to be a specific kind of Model, correct? Not a specific kind of View.

据我所知,它是一种具有与视图交互的特定目的的模型?或者类似的东西?

To my understanding, it's a kind of Model that has a specific purpose of interacting with the View? Or something like that?

我们将不胜感激.

推荐答案

本质上 Model 和 View Model 都是带有属性的简单类.

Essentially Model and View Model are both simple classes with attributes.

这些类的主要目标是为各自的受众(分别是控制器和视图)描述(建模")一个对象.

The main objective of these classes are to describe (to "Model") an object for their respective audiences that are respectively the controller and the view.

所以你说的完全正确

据我所知,这是一种具有特定用途的模型与视图交互

To my understanding, it's a kind of Model that has a specific purpose of interacting with the View

因此,虽然模型类实际上是您的应用程序与之交互的域实体,但视图模型是您的视图与之交互的简单类.

So, while Model classes are effectively Domain Entities that your application interact with, View Models are simple classes that your views interact with.

希望有帮助:)

更新:

Microsoft 开发了 Martin fowler 主要基于模型-视图-控制器的演示模式的专用版本,并将其称为模型-视图-视图模型 (MVVM),用于 PF 应用程序.此模式针对现代 UI 开发平台,在这些平台中,UI 开发人员与传统开发人员相比,更多基于业务逻辑的需求有所不同.看看这里的一些理论

Microsoft has developed a specialized version of the Presentation Pattern by Martin fowler largely based on the Model-View-Controller and called it Model-View-ViewModel (MVVM) for PF application. This pattern is targeted at modern UI development platforms where UI developers have different requirements based more on business logic than traditional developers. Have a look here for a bit of theory

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

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