我试图采用这篇文章http://www.asp.net/signalr/overview/getting-started/tutorial-high-frequency-realtime-with-signalr中的演示,它是用 vS2012 开发的,但是我使用的是 vs2010。我做了模型:
[HubName("moveShapeHub")]
public class MoveShapeHub : Hub
{
public void UpdateModel(ShapeModel clientModel)
{
clientModel.LastUpdatedBy = Context.ConnectionId;
Clients.AllExcept(clientModel.LastUpdatedBy).updateShape(clientModel);
}
}
修改后的 Global.cs:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
RouteTable.Routes.MapHubs();
}
在视图中:
var moveShapeHub = $.connection.moveShapeHub,
$shape = $("#shape"),
shapeModel = {
left: 0,
top: 0
};
moveShapeHub.client.updateShape = function (model) {
shapeModel = model;
$shape.css({ left: model.left, top: model.top });
};
$.connection.hub.start().done(function () {
$shape.draggable({
drag: function () {
shapeModel = $shape.offset();
moveShapeHub.server.updateModel(shapeModel);
}
});
我收到以下错误:无法获取未定义或空引用的属性“客户端”。
知道我做错了什么;将不胜感激您的建议。