Could you tell me why names in Hub-classes are in CamelCase, but in client-side js-code it's in lowerCamelCase? And why I can't call Hello-method from MyHub-class just by MyHub.server.Hello
?
I mean it would be more clear to call the backend-methods be their exact c#-names, isn't it? Does that renaming have any other meaning apart from code-style agreements?
I hope my question is clear enough.
In script.js:
$(function() {
var hub = $.connection.myHub;
hub.client.hello = function (message) { //why not hub.client.Hello ?
alert(message);
}
$("#btn").click(function(){
hub.server.hello(); //why not hub.server.Hello() ??
});
});
In MyHub-class:
public class MyHub : Hub
{
public void Hello()
{
Clients.All.hello(); //why not Clients.All.Hello() ?
}
}
That is due to the naming convention and SignalR proxy codes.
JavaScript is a case-sensitive language where as Dotnet suggests CamelCasing. Calling a method on the server side goes through the proxy codes which is in javascript.