estado luchando con este error la pasta de dos horas ..
TypeError: $.connection is undefined
[Break On This Error]
var chatHubClient = $.connection.chatHub;
aquí es mi Chat.cs (que está en la carpeta del controlador - yo creo que es esto es lo que estoy haciendo mal, pero no puedo encontrar ninguna documentación sobre dónde ponerlo o cómo dirigirlo)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using SignalR.Hubs;
namespace SingalrTest.Controllers
{
public class Chat
{
private readonly static Lazy<Chat> _instance = new Lazy<Chat>(() => new Chat());
public static Chat Instance
{ get { return _instance.Value; } }
}
[HubName("chatHub")]
public class ChatHub : Hub
{
private readonly int TimeoutInSeconds = 30;
private readonly Chat _chat;
public ChatHub() : this(Chat.Instance) { }
private ChatHub(Chat chat)
{
this._chat = chat;
}
public void Join(string channelName)
{
System.Diagnostics.Debug.WriteLine("Someone joined " + channelName);
}
}
}
Y por último, la .. podría _Layout.cs.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>@ViewBag.Title - My ASP.NET MVC Application</title>
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<meta name="viewport" content="width=device-width" />
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/Scripts/jquery-1.8.1.js")
@Scripts.Render("~/Scripts/jquery.signalR-0.5.3.js")
@Scripts.Render("~/signalr/hubs")
<script type="text/javascript">
$(document).ready(function() {
// var chatHubClient = jQuery.connection.chatHub;
var chatHubClient = $.connection.chatHub;
$.connection.chatHub.start(function() {
chatHubClient.join('TEST');
});
});
</script>
</head>
<body>
...
</body>
</html>
Y si visito/signalr/hubs puedo ver que la fuente se ha generado correctamente. Entonces, ¿qué biggy me estoy perdiendo?
Estoy teniendo el mismo problema. Por algún motivo, $ .connection no se define cuando ocurre el evento $ .ready. Lo arreglé de alguna manera al ejecutar mi código en línea en lugar de en el evento listo ... No tengo ni idea de por qué desaparece ... –