How do I refresh view data from inside of a view?
I have a SignalR setup, and I have it where when I press on a button, it will send a message to the server and then the server will then broadcast the message to all clients. The problem I am having is, when a client receives the emission from the server, how can I refresh the data that is on the page? I want it so that when the client receives the server message, it will refresh the data that is being displayed on the homepage. I dont want to refresh the entire page because that kind of defeats the purpose of websockets. Any advice?
3 Replies
https://github.com/ForkEyeee/realtime-poll
i can use js to fetch from a RefreshData Controller and then update the ui, but is there a better way to doit
If you want to do it without reloading the page then yes, you will need to use JS
You can receive JSON with data from the SignalR connection, use it to create a new HTML element, and append it anywhere you need in the DOM
Alternatively, what some frameworks like HTMX, LiveWire, LiveWiew, etc. do, is they send the whole HTML element rendered on the server, so you just append that to the DOM
ok i used js to do it it seems to work fine. seemed kinda scuffed though at first to do it that way thats why i asked