Sunday 25 October 2015

What's the difference between a ViewModel and Controller?

enter image description here
  • The ViewModel can be on the client side as well as server side. Wherever it may be, the sole purpose of viewmodel is to play the presentation data.
  • In MVC architecture Viewmodel is not mandatory but with out controller the request from the client cannot be processed.
  • Controller can be visualised as the main interface between client and server to get any response from the server. It processes the client request, fetches data from repository and then prepares the view data. Viewmodel can be visualised as view data processor/presenter thus an interface to manage the view more eloquently.
  • In the overall context of a web application we can say the controller is the application request handler whereas viewmodel is only the UI handler.