集线器类
public void sendToAll(string UserName,string message,string grpId,string groupName,string UserId)
{
if (grpId == "3")
{
//This is working
Clients.All.MessageReceived(UserName, message, groupName);
}
if (grpId == "4")
{ //This is not working
Clients.Group(groupName).MessageReceived(UserName,message,groupName);
}
}
客户方:
$('#btnSendToAll').click(function () {
var GrpId = $(this).parent().attr('groupid');
var GrpName = $(this).parent().attr('groupname1');
chat.server.sendToAll($("#hdnUserName").val(), $('#txtMsg').val(), GrpId, GrpName, $("#hdnUserId").val());
$('#dvGroupChat', $(this).parent()).find('ul').append($('#txtMsg').val());
$('#message').val('').focus();
});
chat.client.messageReceived = function (name, message, groupType) {
$('div[groupname1=' + groupType + ']').find('ul').append('<ul>' + name + ': ' + message + '');
};