I'm creating an app with ASP.NET Core MVC, Razor, EF Core, SQL Server as the database.
I have 3 views: List
, Create
, and Edit
.
List
- showing the data from the table (as a list)Create
- for creating a new recordEdit
- to edit a selected record
These pages will be accessed by different users.
The case is: how can I update the list without refreshing the List
page? So when there's a new record, the data table will be updated with a new record, even when the record is edited.
I am trying the code with this sample --> https://github.com/dyatchenko/ServiceBrokerListener
But it seems that the page didn't updated.
My code:
public IActionResult Index()
{
var connectionString = this.Configuration.GetConnectionString("SQLConnection");
var listener = new SqlDependencyEx(connectionString, "ProductStatistic", "TrialPurpose", listenerType: SqlDependencyEx.NotificationTypes.Insert);
listener.TableChanged += (o, e) => Console.WriteLine("Your table was changed!");
listener.Start();
var model = _db.TrialPurposeDataViews.FromSqlRaw("exec spTrialPurposeDataView").ToList();
listener.Stop();
return View(model);
}
Did I make a mistake on the code?
Need advice and help, really appreciated.
Thank you.