2

I'm working in ASP.Net Core 2.0 MVC. I need my webpage to always show the latest information from the model. But the information model is constantly updated.

Is there a way to only refresh the page when the model is changed? (Maybe with a OnChange event or AutoResetEvent)

Or is using a timer the only way to refresh the page automatically? Like they do here: How do I refresh the page in ASP.NET? (Let it reload itself by code)

DarkAngel
  • 237
  • 3
  • 14

2 Answers2

4

You need to understand the concepts of request-response and client-server in HTTP. The client first sends a request to the server. The server then sends an appropriate response back to the client. At that point, typically, the communication is done. The server moves on to other tasks, and the client renders the response it received from the server and waits for further user interaction. The server is not capable of and does not even care about updating the client. As a result, to get new information, the client must make a further request to the server. This can be done by causing an actual page refresh using JavaScript or the meta refresh tag, or you can issue an AJAX request, without causing the whole page to reload.

Now, with HTML5, there's web sockets (combined with something like SignalR on the backend) that can allow the server to actually push new information to the client. However, you have to implement that yourself.

Chris Pratt
  • 232,153
  • 36
  • 385
  • 444
1
location.reload()

will refresh an HTML page with JavaScript

But I don't think that's what you need.

Does the page model change on the server or on the client?

If it changes on the client, you need AJAX to send it asynchronously to the server.

If it changes on the server, you should look at web sockets as a way to communicate to the client the changes that have been made.

mykeels
  • 590
  • 5
  • 9