Interviews - C# Corner

Arunava Bhattacharjee
What is ViewModel in MVC?Why we need a "ViewModel" in MVC? Is MVC similar to MVVM then?
By Arunava Bhattacharjee in ASP.NET MVC onSep 24 2014
  • lakshmana poojary
    Sep, 2014 25

    View Model in MVC is used in situation where we want to use the multiple model instance in single form or view page. View model will have the multiple model property. Those properties can be used using Razor syntax and in the Controller post action we can separate the properties into required individual model and save the data into different model simultaneously.

    • 1
  • Gokul Rathod
    Nov, 2014 25

    View Model is MVC model which will hold the data of respective class

    • 0
  • Arunava Bhattacharjee
    Sep, 2014 25

    The View-Model is a composite of the abstraction of you view's state and behavior. The idea behind the View-Model is to create an abstraction of your view which has little to no dependencies on your view. There should be no references to UI controls or classes specific to the UI. There should be no event handlers like what is common in a code-behind class.For example, If a Customer object has fifty properties, but one component only shows their name, then we create a custom ViewModel type with only those two properties. Because we only have one ViewModel type per View, we shape our ViewModel around only what is displayed (or used) in that View. For one, just having a ViewModel points us to the right View. We need any other information other than your ViewModel type to pick the correct View. This also means we no longer need to concern ourselves with locating views by some arbitrary name, as the ViewModel is the View. Things like RenderPartial,which I have to select a name, become rather pointless at that point.

    • 0

Most Popular Companies

Most Popular Job Functions

MOST LIKED QUESTIONS