模型和视图模型之间的区别 [英] difference between models and view models
问题描述
我一直在研究asp.net MVC项目结构的一个新的项目,并有一个关于事情的问题是混淆了我。什么是模型和视图模型之间的区别?我会说,视图模型的形式特性包括模型是正确的?
I have been researching asp.net MVC project structure's for a new project and have a question about something is confusing me. What is the difference between models and view models? Would I be correct in saying that view models encompass models in the form properties?
推荐答案
我有一个博客,我想显示的最新文章的最新评论的名单,日志分类的单一视图。我该怎么办呢?我能强烈地键入我的看法,以模型正确的呢?说到这里的视图模式的
I've a blog where I want to display the list of the latest posts, latest comments, post categories in a single view. How I can do that? I can strongly type my view to any one of the model right? There comes view model.
我创建 BlogViewModel
称为视图模型,包含最新的帖子,最新的评论和其他的东西,属性和我结合我的这个模型视图。在帖子
,注释
..是的域模型的,而 BlogViewModel
是的视图模型的我创建了专为视图。
I created a view model called BlogViewModel
that contains latest posts, latest comments and other stuff as properties and I bind my view with this model. The posts
, comments
.. are domain models while the BlogViewModel
is the view model I created specially for the view.
明天我会告诉我的博客在移动版本,在那个时候我可能会创建一个只包含较少的一个简单视图模型。最后..查看模型是观点和大多数时候,他们充当了真正的域模型包装!
Tomorrow I'll show my blog in a mobile version and at that time I may create a simple view model that contains only less properties. Finally.. view models are for views and most of the times they acts as wrappers over the real domain models!
这篇关于模型和视图模型之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!