difference between models and view models

后端 未结 4 623
陌清茗
陌清茗 2020-12-29 13:05

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 vie

4条回答
  •  [愿得一人]
    2020-12-29 13:24

    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.

    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!

提交回复
热议问题