是视图模型在asp.net媲美视图模型在WPF [英] Is the ViewModel in asp.net comparable to the ViewModel in WPF

查看:105
本文介绍了是视图模型在asp.net媲美视图模型在WPF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您知道WPF MVVM模式,那么你知道约什 - 史密斯的MSDN文章,其中一个CustomerViewModel不举行简单的属性,如:

If you know the MVVM pattern for WPF then you know Josh smith msdn article where a CustomerViewModel does not hold a simple property like:

public string FirstName {get;set;}

而是一个视图模型包装模型和代表这样的属性访问:

Rather a ViewModel wraps a Model and delegates the property access like this:

public string FirstName
{
    get { return _customer.FirstName; }
    set
    {
        if (value == _customer.FirstName)
            return;
        _customer.FirstName = value;
        base.OnPropertyChanged("FirstName");
    }
}

我没有在asp.net mvc的看到了这一点。这是由于缺少INotifyPropertyChanged接口?

I have not seen this in asp.net mvc. Is this due to the missing INotifyPropertyChanged interface?

推荐答案

这MVVM的视图模型模式件在MVC使用时比不同的定义

The ViewModel and Model pieces from MVVM have a different definition than when used in MVC

在MVVM中,视图模型是您的应用程序,而查看只是提供了一个友好的用户界面为它。在MVC中,查看是您的应用程序,因为它的视图模型提供的数据,而控制器处理应用程序的流程和逻辑。

In MVVM, the ViewModel is your application, while the View just provides a user-friendly interface for it. In MVC, the View is your application, the ViewModel provides data for it, and the Controller handles application flow and logic.

的模型也是两个图案之间的不同。在MVC中, M 重新presents两个数据模型和视图模型,而在MVVM的 M 只重presents数据模型。

The Models are also different between the two patterns. In MVC, the M represents both data models and view models, while in MVVM the M only represents data models.

要总结,MVC的 M +ç等于MVVM的 VM 和MVC的中号包含MVVM的 M的组合 VM

To summarize, MVC's M+C is equal to MVVM's VM, and MVC's M contains a mix of both MVVM's M and VM pieces

作为一个侧面说明, INotifyPropertyChanged的接口由WPF来自动更新UI时属性的变化。这种事情是不是在MVC中使用,因此没有必要的。

As a side note, the INotifyPropertyChanged interface is used by WPF to automatically update the UI when a property changes. This sort of thing is not used in MVC, so not needed.

这篇关于是视图模型在asp.net媲美视图模型在WPF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆