In the simplest of terms, I like to think about the following:
Model: Strictly looks and looks like your data model. In every sense and purpose, this is just a representation of the class of your data model. He does not know your representation or any elements in your representation. However, it should not contain attribute decorators (i.e. Required, Length, etc.) that you would use for your presentation.
View Model: Serves as a link between your view and your model, and in many cases is also a wrapper for your model. This will be useless without presentation, so it usually cannot be reused for multiple views and controllers, such as the standard model.
As an example, your model can have the following properties, which are direct representations of your data source:
public string FirstName { get; set; } public string LastName { get; set; }
Now, since your View model is tied to your view, it can have the following property - which combines the Model FirstName field and the LastName field together as one line:
[Display(Name = "Customer Name")] public string CustomerFullName { get { return String.Format("{0} {1}", myModel.FirstName, myModel.LastName) }}
Jason Marsell Sep 14 '13 at 23:24 2013-09-14 23:24
source share