Tuesday, 22 January 2013

Purpose of using ViewModel in MVC


The one and only purpose of a Viewmodel class is to contain (strongly typed) data to be sent to a view by an action method.
So as the answers in your referred question suggest create a Viewmodel class which contains properties for all the data you need in your view.
The advantage of Viewbag usage is that you don't have the overhead to create a separate class. The disadvantage is that you don't have compile time type checking and intellisense available.

No comments:

Post a Comment