Problem: I want to monitor incoming data from a subscription without having to refresh the page.
Using RazorPages.
At the minute I have a very simple app:
(code behind)
public class PageModel
{
public List<string> dataList = new List<string>();
public void OnGet()
{
var mySubscriber = Subscriber.subscribe(actionMethod);
}
private async Task actionMethod(string data)
{
dataList.Add(data);
}
}
(page)
@foreach(var s in Model.dataList){
<div>@s</div>
}
The subscriber calls the actionMethod
whenever a new string is received.
However currently, this is static and once the page loads, I have to refresh the page to get more data.
How to refactor this so that the page automatically updates with new data?