2
votes

I have create an asp.net core mvc / server side blazor web application.

I have an sql-server database with entityframework core.

I want to display a table content in a page. I have follow WeatherForecastService example. Everything works fine.

What i want to do is to auto refresh the listing if another user is inserting, updating or deleting an item in the database.

I think there is a way to do that with signalR, but is there a simple way to do that automatically with Blazor ?

Thanks

1
Could you not just poll the service and assign the data model to the result of the service? You may need to call StateHasChanged() to actually update the data model. This is probably not a very clean way but the simplest I can think of.Chris Campbell

1 Answers

1
votes

I'm not aware of an automatic way to do that. Handling data should be in your control always.

The way I've seen this done is a SignalR hub that pushes updates to all connected clients when a CUD operation happens. Then, the code in the view determines what to do (e.g., of the user is editing an item someone else edited or deleted). Otherwise, just apply the operation to the viewmodel data.