Hi!
I have a problem with SignalR and the Grid.
I have a hub like this:
01.public class ACTaskHub : Hub02.{03. private IMemoryCache taskCache;04. 05. public ACTaskHub(IMemoryCache cache)06. {07. taskCache = cache;08. }09. 10. public override Task OnConnectedAsync()11. {12. //Groups.AddToGroupAsync(Context.ConnectionId, GetGroupName());13. return base.OnConnectedAsync();14. }15. 16. public override Task OnDisconnectedAsync(Exception exception)17. {18. //Groups.RemoveFromGroupAsync(Context.ConnectionId, GetGroupName());19. return base.OnDisconnectedAsync(exception);20. }21. 22. public IEnumerable<TaskViewModel> Read()23. {24. var tasks = taskCache.Get("tasks") as IEnumerable<TaskViewModel>;25. 26. if (tasks == null)27. {28. var products = AppData.TaskList.Select(t => new TaskViewModel29. {30. ID = t.ID,31. Name = t.Name,32. LastRunTime = t.LastRunTime,33. Duration = t.Duration,34. Schedule = t.Schedule,35. Status = t.Status.ToString(),36. Result = t.LastResult,37. Exception = t.Exception?.Message,38. CreatedAt = DateTime.Now.AddMilliseconds(1)39. });40. 41. tasks = products.ToList();42. taskCache.Set("tasks", tasks, TimeSpan.FromMinutes(30));43. }44. 45. return tasks;46. }47. 48. public TaskViewModel Create(TaskViewModel task)49. {50. //task.ID = Guid.NewGuid();51. //product.CreatedAt = DateTime.Now;52. //product.Category = product.Category ?? new CategorySignalR() { CategoryID = 1 };53. 54. //Clients.OthersInGroup(GetGroupName()).SendAsync("create", task);55. Clients.Others.SendAsync("create", task);56. 57. return task;58. }59. 60. public void Update(TaskViewModel task)61. {62. //Clients.OthersInGroup(GetGroupName()).SendAsync("update", task);63. Clients.Others.SendAsync("update", task);64. }65. 66. public void Destroy(TaskViewModel task)67. {68. //Clients.OthersInGroup(GetGroupName()).SendAsync("destroy", task);69. Clients.Others.SendAsync("destroy", task);70. }71. 72. //public string GetGroupName()73. //{74. // return GetRemoteIpAddress();75. //}76. 77. //public string GetRemoteIpAddress()78. //{79. // return Context.GetHttpContext()?.Connection.RemoteIpAddress.ToString();80. //}81.}
And i use Kendo Grid with SignalR datasource to show the hub data like this:
@(Html.Kendo().Grid<TaskViewModel>() .Name("TaskList") .Columns(columns => { columns.Bound(t => t.Name).Width(140); columns.Bound(t => t.LastRunTime).Format("{0:yyyy-MM-dd hh:mm:ss}").Width(150); columns.Bound(t => t.Duration).HtmlAttributes(new { style = "text-align:right" }).Width(130); columns.Bound(t => t.Schedule).Width(100); columns.Bound(t => t.Status).Width(80); columns.Bound(t => t.Result).Filterable(false).Width(250); columns.Bound(t => t.Exception).Filterable(false).Width(150); }) .Sortable() .Scrollable() .Filterable() .Resizable(resize => resize.Columns(true)) .HtmlAttributes(new { style = "maxheight:530px;" }) .DataSource(dataSource => dataSource .SignalR() .AutoSync(true) .Events(events => events.Push("onPush")) .Events(events => events.Error("onError")) .Sort(s => s.Add("CreatedAt").Descending()) .Transport(tr => tr .Promise("hubStart") .Hub("hub") .Client(c => c .Read("read") .Create("create") .Destroy("destroy") .Update("update")) .Server(s => s .Read("read") .Create("create") .Destroy("destroy") .Update("update"))) .Schema(schema => schema .Model(model => { model.Id("ID"); model.Field("ID", typeof(string)).Editable(false); model.Field("CreatedAt", typeof(DateTime)).Editable(false); model.Field("Name", typeof(string)).Editable(false); model.Field("LastRunTime", typeof(DateTime)).Editable(false); model.Field("Duration", typeof(TimeSpan)).Editable(false); model.Field("Schedule", typeof(string)).Editable(false); model.Field("Status", typeof(string)).Editable(false); model.Field("Result", typeof(string)).Editable(false); model.Field("Exception", typeof(string)).Editable(false); }) ) ))
The hub is connected and the data are loaded, but not visible in the grid. I can see the like of my task in the grid because of mouse hovering but the fields are empty. (see screenshot1.png)
The secound problem i have is, that when the data is updated from server the client want to invoke "create" method. Why is the client doing this?
I get this error message: (see screenshot2.png)
And why is the ASP.NET Core Grid SignalR demo not working: https://demos.telerik.com/aspnet-core/grid/signalr
