Tuesday, 2 July 2013

ViewModel in mvc3

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
    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. 

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


  1. 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.

  2. You 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...
    ios App Development Company
    Android App Development Company



ADFS (1) ADO .Net (2) Ajax (1) Angular (1) Angular Js (17) Angular2 (28) ASP .Net (14) Authentication (1) Azure (1) Breeze.js (1) C# (50) CD (1) CI (2) CloudComputing (1) CMS (1) CSS (2) Design_Pattern (3) DevOps (4) DI (4) Dotnet (22) Entity Framework (3) ExpressJS (4) Html (3) IIS (1) Javascript (6) Jquery (8) Lamda (3) Linq (11) Mongodb (1) MVC (50) NodeJS (7) RDLC (1) Report (1) SDLC (1) Sql Server (30) SSIS (3) SSO (1) SSRS (2) UI (1) WCF (13) Web Api (11) Web Service (1) XMl (1)