What role does MVVM play in ASP.NET MVC 4 web applications?

前端 未结 5 1007
心在旅途
心在旅途 2021-02-14 03:17

While I\'m reading the book \"ASP.NET MVC 4\" I\'m wondering about MVVM. I started googling and cannot find any books about developing web applications using MVVM, so I must be

5条回答
  •  感情败类
    2021-02-14 04:05

    MVVM is the standard design pattern for WPF/Silverlight development, and should not be confused with MVC for ASP.Net development.

    The two may sound similar and share some common parts, but they are two different design patterns.

    From what I learned about knockout.js, it was designed to create "data bindings" similar to what you would use in WPF/Silverlight development, which is why the MVVM design pattern applies there.

    To quote from another answer of mine regarding the differences between MVVM and MVC

    In MVVM, your code classes (ViewModels) are your application, while your Views are just a pretty user-friendly interface that sits on top of the application code and allows users to interact with it. This means the ViewModels have a huge job, because they are your application, and are responsible for everything from application flow to business logic.

    With MVC, your Views are your application, while your Controller handles application flow. Application logic is typically found in ViewModels, which are considered part of the M in MVC (sidenote: the M in MVC cannot be considered the same as the M in MVVM because MVC's M layer contains more functionality than MVVM's M layer). A user is given a screen (View), they interact with it then submit something to the Controller, and the Controller decides who does what with the data and returns a new View to the user.

提交回复
热议问题