2

I'm taking an online MVC course and the instructor is describing use of a "pure ViewModel". (Instructor is not responsive to questions so I'm asking here. He is also using Entity Framework Code First methodology.) He started this discussion based on setting (manual) default values for Add forms rather than taking the default from the Model.

What is the point/benefit of using the pure ViewModel?

maccettura
  • 10,514
  • 3
  • 28
  • 35
Nestor
  • 17
  • 3

2 Answers2

1

It's just a guess, but he could mean the total separation of ViewModels from Business Models and also from Database entities/objects/models.

ViewModels can be described as pure because they have one goal: to serve an MVC View (e.g. OrderList.cshtml) with data, and possibly to get data back from the View, while being separated from all other types of models that serve different purposes.

The separation has benefits:

  • In order to display different data in the View, only the ViewModel needs to be changed (+ how it is initialized) without changing Business or Entity models.
  • And vice versa: if Business or Entity models change, it could suffice to only alter the mapping that initializes the same good old ViewModel, that can still serve the same good old View with data.
Peter B
  • 22,460
  • 5
  • 32
  • 69
0

ViewModels are used to separate logic from view and use additional attributes and props for validation. Please read articles below to get more understanding

Big article about separation views

Small article about validation

Ivan Maslov
  • 168
  • 2
  • 13