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

查看:29
本文介绍了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 SignalRsignalr/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/hubs 正在被引用,我可以看到 JS 代码,它没有抛出任何错误.但是引用 $.connection 会抛出一个 Uncaught TypeError: Cannot read property 'tenantHub' of undefined.还尝试执行默认聊天示例,它给出了相同的错误.在 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")] 从您的课程中删除.如果我把这些放在那里,我的就行不通了.还可以尝试将集线器放入项目根目录下名为 "Hubs" 的文件夹中.

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天全站免登陆