MVC模型通知更改视图 [英] MVC Model Notifying View of changes

查看:116
本文介绍了MVC模型通知更改视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试开发一种非常简单的消息传递表单(MVC C#表单),其中该表单显示用户拥有多少未读消息.如果要在我的模型列表中添加一条新消息,您如何通知视图(哪些方法)?我似乎对此不敢理

I'm trying to develop a very simple messaging form (MVC C# forms), in which a form displays how many unread messages a user has. If a new message was to come into the list in my model, how do you notify the view (which methods)? I can't seem to get my head round this.

推荐答案

如果您正在谈论C#Windows窗体应用程序,那么您要使用的是观察者模式.有关模式,请参见此处.基本上,您想让您的控制器通过观察者模式向模型注册,以便将可能导致视图过时的任何模型更改通知给我们.然后,控制器可以通知视图重新渲染受影响的部分.

If you are talking about a C# windows forms application then what you want to use is the Observer pattern. See here for the pattern. Basically you want to have your controller register with the model via the observer pattern to be notified of any model changes that can cause the view to be obsolete. Then the controller can notify the view to re render the affected portion.

这篇关于MVC模型通知更改视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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