Fundamental MVVM

added by dpeterson
8/23/2011 4:04:20 PM

218 Views

John Papa goes to great lengths to write an MVVM introduction for "the rest of us". He forgoes the heady, lengthy explanation and gives us a concrete sample that is easy to understand. For anyone who doesn't know the MVVM pattern, or is having difficulty understanding it or how it is useful, this post is for you.


2 comments

vijayst
8/23/2011 8:29:06 PM
There is always a clear distinction between the Model and the ViewModel. The View requires a model specific to the View. Creating such a model is the ViewModel. The post describes this difference really well.

I have been working with ASP.NET MVC for over a year now. The more I work with it, the more I am inclined to use the Model in MVC (more) as a ViewModel. For projects with complex UI, a ViewModel (folder) should exist and should be separate from the Model folder. ViewModels can have DataAnnotations and UI specific logic. Models are more tied with the data entities.

dpeterson
8/24/2011 3:06:43 PM
MVC and MVVM are not all that different, really. The main conceptual difference is that rather than directly interacting with the View, the ViewModel's properties are subscribed to and bound to the controls on the View. Doing things that way provide loose coupling between the View and ViewModel, which you don't necessarily have between the View and the Controller in MVC.