Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between models and view models

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?

like image 626
amateur Avatar asked Jun 26 '12 17:06

amateur


People also ask

What is the difference between model and view in MVC framework?

Model View Controller (MVC) : This Model is the central component of this architecture and manages the data, logic as well as other constraints of the application. The View deals with how the data will be displayed to the user and provides various data representation components.

What is meant by ViewModel?

A view model or viewpoints framework in systems engineering, software engineering, and enterprise engineering is a framework which defines a coherent set of views to be used in the construction of a system architecture, software architecture, or enterprise architecture.

What is the difference between controller and ViewModel?

The model is responsible for managing the data of the application. It receives user input from the controller. The view renders presentation of the model in a particular format. The controller responds to the user input and performs interactions on the data model objects.

What is the purpose of ViewModel?

The purpose of the ViewModel is to acquire and keep the information that is necessary for an Activity or a Fragment. The Activity or the Fragment should be able to observe changes in the ViewModel. ViewModels usually expose this information via LiveData or Android Data Binding.


1 Answers

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!

like image 113
VJAI Avatar answered Sep 21 '22 06:09

VJAI