SignalR:$ .connection未定义 [英] SignalR: $.connection is undefined

查看:262
本文介绍了SignalR:$ .connection未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MVC4应用程序中使用Visual Studio 2012 Ultimate RC,SignalR 0.5.1和Jquery 1.7.2。

I'm using Visual Studio 2012 Ultimate RC, SignalR 0.5.1 and Jquery 1.7.2 in an MVC4 application.

我看过: MVC4 SignalR signalr / hubs 501未实现错误

但这不会影响我的问题(我正在使用IIS Express进行调试)。

But it does not affect my issue (I am using IIS Express to debug).

当我尝试使用SignalR时,未定义$ .connection变量。我的服务器端代码:

When I try to utilize SignalR the $.connection variable is undefined. My server side code:

[HubName("tenantHub")]
public class TenantHub : Hub
{
    ...
    void TenantChange(CrudAction action, Tenant tenant)
    {
        Clients.eventOccurred(action.ToString(), tenant);
    }
}

客户端:

$(function() { var test = $.connection.tenantHub; });

正在引用客户端 SignalR / hub 而且我可以看到JS代码,它不会引发任何错误。但是引用$ .connection会引发 Uncaught TypeError:无法读取未定义的属性 tenantHub 。还尝试做默认的聊天示例,它给出了相同的错误。在VS2012中使用时,SignalR是否不受支持?还是我很笨?

Client side SignalR/hubs is being referenced and I can see the JS code, it does not throw any errors. But referencing $.connection throws a Uncaught TypeError: Cannot read property 'tenantHub' of undefined. Also tried to do the default chat example, it gives the same error. Is SignalR unsupported when utilized in VS2012 or am I just being stupid?

推荐答案

尝试从您的计算机中删除 [HubName( tenantHub)] 类。如果我在那儿,我的就不会工作。也可以尝试将集线器放入项目根目录下的名为集线器 的文件夹中。

Try taking [HubName("tenantHub")] off your class. Mine wouldn't work if I had those on there. Also try putting your hubs into a folder called "Hubs" at the root of your project.

这篇关于SignalR:$ .connection未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆