I need to control displaying a hidden label(a message) in admin side of my MVC site so that all online clients browsers will be able to see the message immediately without refreshing their browsers manually. In detail, once I change a setting in my page and hit save button, I'd like that a hidden label in a partial view(site header) be displayed to all connected browsers immediately. I already know few ways which don't seem great:
<meta http-equiv="refresh" content="5"> in page head which causes keep refreshing whole page and is not what I'm trying to achieve.
have a js
setInterval() function which makes ajax call to an action every few seconds and gets the latest value of the settings from the action then changes the label hidden value in js file if needed. This causes more traffic between client and server and also prevents sessions from being expired due to ajax call.
I am wondering if there is a proper way to achieve this.
You are going to need to implement a socket connection between your server and all clients. Then you can send a broadcast containing the message to all clients.
Have a look here for example: http://socket.io/docs/