anthonypliu
anthonypliu

Reputation: 12437

Cannot connect to hub class

I have the following script include:

<script src="@Url.Content("~/signalr/hubs")" type="text/javascript"></script>

I have a hub class like so:

public class Dashboard : Hub, IDisconnect, IConnected
{
}

I am trying to connect to it on client side like this:

$(function () {
    $.connection.Dashboard.start(function () { 

    });
});

but I am getting a javscript error:

TypeError: $.connection.Dashboard is undefined

What am i doing wrong?

Upvotes: 0

Views: 105

Answers (2)

Drew Marsh
Drew Marsh

Reputation: 33379

@pollirrata is correct, the default naming rules will init-lower case the name of your Hub on the client side to match typical JavaScript conventions. That said, if you want to control the exact name of your hub explicitly you can apply the HubNameAttribute like so:

[HubName("Dashboard")]
public class Dashboard : Hub, IDisconnect, IConnected 
{
}

Upvotes: 2

pollirrata
pollirrata

Reputation: 5286

The name of your hub is treated as lowercase on the javascript code. Have a look on the wiki sample

So in your case you should be using dashboard instead of Dashboard

Upvotes: 1

Related Questions