Skip to content Skip to sidebar Skip to footer

Signalr Call From Controller

I'm needing to pass strings from my controller to a signalR hub and have it render on my page. I've followed along with the chat tutorial found at: https://docs.microsoft.com/en-us

Solution 1:

await _errorHub.Clients.All.SendAsync("SendMessage", message);

"SendMessage" should be "ReceiveMessage"

Solution 2:

You are calling _errorHub.Clients.All.SendAsync("SendMessage", message) in your controller instead of _errorHub.SendMessage(message). This means you're controller directly is invoking SendMessage on your clients, but you're client is only listening to ReceiveMessage.

So, you'll want to call _errorHub.SendMessage(message) in your controller, which in turn calls Clients.All.SendAsync("ReceiveMessage", message) which will trigger your clients ReceiveMessage method

Post a Comment for "Signalr Call From Controller"