Search code examples
asp.net-mvcasp.net-mvc-2modelviewmodel

ASP.NET MVC Model vs ViewModel


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?

Some clarification would be appreciated.


Solution

  • 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.

    So you are completely right when you say

    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.

    Hope it helps :)

    Update:

    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