I'm trying to update a PartialView when a register is updated in DataBase. I'm using SqlDependency and the event rise properly when the change happens.
SqlDependency.OnChange += new OnChangeEventHandler(sqlDependency_OnChange);
Method:
Private void sqlDependency_OnChange(object sender, SqlNotificationEventArgs e)
{
System.Diagnostics.Debug.WriteLine("Ok");
UpdateView();
}
And the method that is called:
public ActionResult UpdateView()
{
try
{
//Blablabla...
//Business logic...
//Blablabla...
model = 2;
return PartialView(model);
}
catch (Exception ex)
{
return PartialView(0);
}
}
I receive every time a change is made the Lines in the OutputWindow, the method UpdateView() exits with no errors, but the PartialView is not render any more.
The View:
@model int
<h4>You have @Model points.</h4>
What I'm doing wrong? Is it because I'm requesting the Render from a different thread? Can I Update a View from server side when an event occurs? Thanks for your help!