locked
Creating method in hub that can be called from a view RRS feed

  • Question

  • User1181131379 posted

    Hi all!

    I'm experimenting with SignalR and liking it so far, quite a lot. I was thinking that i wanted to add a method to my hub, for example a method like this:

    public void Uonline(string roomId)
    {
    
    Clients.OthersInGroup(roomId).online("test", "test2");
    
    }
    

    The thought here is to be able to when clicking a button retrieve the clients currently connected and present them. But my question is how to run this method from the view? I have another one at the moment called Notify with 4 parameters, doing almost the same thing. I can access this one by writing:

    chat.server.notify(para1, para2, para3, para4);

    However if trying to do the same with my new method

    chat.server.uonline(param1);

    I only get a method not found error in the JS-console.

    Sorry for such a newbe question, but I cant seem to figure this out!

    Wednesday, March 22, 2017 6:18 PM

All replies

  • User-1838255255 posted

    Hi RobertRoos,

    I reproduce the issue on my side by declaring a new method named Uonline and calling this method on JavaScript client, the code works fine. As far as I know, to make hub methods visible on the client, the hub implementation and methods must be declared as public, please check your hub method definition again and make sure it is declared as public. Besides, you could try to define a new hub class with methods or use the HubName attribute to specify a different name for clients to use, and test if the method could be called.

    [HubName("CustomerChatHub")]
    public class ChatHub : Hub
    


    Best Regards,

    Eric Du

    Thursday, March 23, 2017 9:32 AM