简体   繁体   中英

How to notify the views when the database changes? (MVC, C#)

I'm thinking on a good design which is based on MVC and works with databases, but I have no idea how to notify the views of certain database-changes.. What technique to use, do I need more layers or not? How would you implement these?

Insert: 插入

Update: 更新资料

Is it even possible, or should I stick to a refresh button on the views?

To make this more complicated, what if I have a view, about which I know it lists people, but I don't know if it displays the people's interests from another table? The view would just use the "Interests" property of the Person class, which then lazyloads the interests. Then if the name of an interest changes, the Central model notifies the views which list surely interests, but how to find out if there is a view which displays interests too?

Tohu va bohu is what is in my head now.

通过javascript从视图检查db的最新状态更适用。

In a Client - Server model (Asp.Net, web services etc), the client need to request the server for any information. Server wouldn't notify the client in any way.

May be you can implement an Ajax request periodically polling for the server/database changes.

Try something like a client script running every minute, to repeat requesting for the server changes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM