0

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?

4

2 回答 2

2

@pollirrata 是正确的,默认命名规则将在客户端初始化您的集线器的小写名称以匹配典型的 JavaScript 约定。也就是说,如果您想明确控制集线器的HubNameAttribute确切名称,您可以这样应用:

[HubName("Dashboard")]
public class Dashboard : Hub, IDisconnect, IConnected 
{
}
于 2012-08-09T20:44:20.500 回答
1

您的集线器名称在 javascript 代码中被视为小写。查看wiki 示例

所以在你的情况下,你应该使用dashboard而不是Dashboard

于 2012-08-09T20:36:01.373 回答