In asp.net mvc, a controller can pass single object to the corresponding view. This object may be a simple object or a complex object. ViewModel is a complex object that may contain multiple entities or objects from different data models or data source. Basically ViewModel is a class that specify data model used in the strongly-typed view. It is used to pass data from controller to strongly-typed view.
Key Points about View Model
Some Tips for using ViewModel
In ViewModel put only those fields/data that you want to display on the view/page.
Since view reperesents the properties of the ViewModel, hence it is easy for rendering and maintenance.
Use a mapper when ViewModel become more complex.
ViewModel help us to organize and manage data in a strongly-typed view with more flexible way than complex objects like models or ViewBag/ViewData objects.
Other Links Related to ViewModel are :
1- what-is-model-and-viewmodel-in-mvc
Key Points about View Model
ViewModel contain fields that are represented in the view (for LabelFor,EditorFor,DisplayFor helpers)
ViewModel can have specific validation rules using data annotations or IDataErrorInfo.
ViewModel can have multiple entities or objects from different data models or data source.
ViewModel can have specific validation rules using data annotations or IDataErrorInfo.
ViewModel can have multiple entities or objects from different data models or data source.
In ViewModel put only those fields/data that you want to display on the view/page.
Since view reperesents the properties of the ViewModel, hence it is easy for rendering and maintenance.
Use a mapper when ViewModel become more complex.
ViewModel help us to organize and manage data in a strongly-typed view with more flexible way than complex objects like models or ViewBag/ViewData objects.
Other Links Related to ViewModel are :
1- what-is-model-and-viewmodel-in-mvc
View model of MVC3 is really a complex object or as a class, this blog contribute helpful lines for mvc3 developer, it is used for good .NET MVC3 Development by xicom technologies.
ReplyDeleteYou have provided an nice article, Thank you very much for this one. And i hope this will be useful for many people.. and i am waiting for your next post keep on updating these kinds of knowledgeable things...
ReplyDeleteios App Development Company
Android App Development Company