ASP.Net MVC和MVVM [英] ASP.Net MVC and MVVM

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

问题描述

MVVM是在ASP.Net MVC之前存在的Microsoft设计模式.任何人都可以通过MVVM和新的MVC模式之间的区别来了解吗?

MVVM is a Microsoft design pattern that existed before ASP.Net MVC. Can anyone through light on differences between MVVM and the new MVC pattern?.

推荐答案

任何人都可以阐明MVVM与新MVC模式之间的区别吗?

Can anyone throw light on differences between MVVM and the new MVC pattern?.

是:使用ASP.NET MVC时,MVC模式使用控制器将模型直接呈现到视图中.对于带有少量对象的琐碎项目,这是完全可以接受的.可能会出现问题的地方是,UI层的问题可能会渗入到基础(域)模型中.

Yes: When using ASP.NET MVC the MVC pattern uses the controller to render the model directly into the view. This is perfectly acceptable for trivial projects with a small number of objects. Where this can become a problem is that the concerns of the UI layer can bleed through to the underlying (domain) model.

使用MVVM时,您将在模型和视图之间添加一个抽象,这当然是ViewModel.这允许作者将视图中最容易使用的对象投影到视图中. ViewModel可以包含在(域)模型中不适当的内容.与之相关的成本是,您需要具有映射逻辑,该逻辑将数据从模型转换为视图模型.诸如AutoMapper之类的工具可以帮助您完成这项工作.

When using MVVM then you are adding an abstraction between the Model and the View, which is of course the ViewModel. This allows the author to project into the view an object that is most readily consumed by the view. The ViewModel can contain things which would be out of place in the (domain) Model. The cost associated here is that you need to have mapping logic which transposes the data from the model to the View Model. Tools like AutoMapper can assist with this chore.

一个简单的例子可能是Model不需要某些特定字段,而特定View则需要.如果此逻辑已附加到ViewModel,则无需将其烘焙到用户界面中,而是其他UI可以使用相同的VM,而不必复制烘焙到第一个用户界面中的逻辑.

A simple example of this might be the Model doesn't require certain fields as required, but a particular View does. Rather than baking this logic into the user interface, if it is attached to the ViewModel, then other UI's can consume the same VM without having to duplicate logic that was baked into the first user interface.

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

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