2.2.6.Creating a client method and calling from server
[HubName("myhub")]
public class MyHub:Hub
{
public void serverMethod(string msg)
{
Clients.All.clientMethod(msg + " good morning");
//return msg + " good morning";
}
public MyHub()
{
//
// TODO: Add constructor logic here
//
}
}<script>
$(document).ready(function () {
var obj = $.connection.myhub;
obj.client.clientMethod = function (data) {
alert(data);
}
$.connection.hub.start().done(function () {
obj.server.serverMethod("Hi");
});
});
</script>Previous2.2.5.Passing parameters to server method from clientNext2.3. Exploring the class hub and group chat
Last updated