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

前端 未结 5 1004
心在旅途
心在旅途 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 03:57

    I have used MVVM in desktop applications and I have a property in my viewmodels named Model where I store a business object as the model. My views have a property named DataContext where the viewmodels are stored before the views are loaded. A view bind its controls to the business object using the path DataContext.Model.BusObjPropertyName. I have a UserInteractionService that register from the start the relationships between views and viewmodels. When a viewmodel needs to show another viewmodel, it calls the method ShowView in the UserInteractionService and pass the viewmodel as parameter. Then the service instantiate the view corresponding to the viewmodel received, set its DataContext property with the viewmodel and show it.

    If it is possible to do the bindings to a path like that above in Asp, all this model can be reused either in desktop as in Web applications.

提交回复
热议问题