Search code examples
c#signalrsignalr-hub

How to send data back into SignalR Hub


is it possible to directly send data back into SignalR Hub from the front end JS/JQ (im working with lists and monitoring). For example take textbox input and plug it back into a list on the back end of the server? If any one can drop that 1 liner execution line would be also appreciated thanks.


Solution

  • Yes, I assume you have something in your javascript like:

    var chat = $.connection.signalRPushEvents;
    

    Then later on you can do this in Javascript:

    chat.server.BroadcastData(a, b, c);
    

    Then the class you're extending Microsoft.AspNet.SignalR.Hub with should contain a method with that signature which is what that Javascript will effectively be calling.

    public void BroadcastData(int a, string b, double c)
    {
        // Do something with Clients or whatever here
    }