Search code examples
signalrsignalr-hub

Getting a javascript error : chat.server.ConnectClient(clientName); is not a function


why am i getting this error :

myhub.cs:

  public class ChatHub : Hub
{
 private static DataTable ConnectedClientDt = null;

  public void ConnectClient(string ClientName)
  {
    if (ConnectedClientDt == null)
    {
        ConnectedClientDt = new DataTable();
        ConnectedClientDt.Columns.Add("ClienID");
        ConnectedClientDt.Columns.Add("ClientName");
    }
    ConnectedClientDt.Rows.Add(Context.ConnectionId,ClientName);

}

ClientSide :

 $(document).ready(function () {
        var chat = $.connection.chatHub;
        var clientName = '<%=Session["ClientName"] %>';

        $.connection.hub.start().done(function () {
            chat.server.ConnectClient(clientName);

        });

any help please


Solution

  • Change the name to lowercase. ConnectClient should be connectClient. It can be confusing at first be we make the names javascript friendly names (camel case)