2.2.4.Create A server method and calling from client

  • 1.Add a simple method in App_Code\MyHub.cs

[HubName("myhub")]
public class MyHub:Hub
{
    public string serverMethod()
    {
        return "serverMethod";
    }
    public MyHub()
    {
        //
        // TODO: Add constructor logic here
        //
    }
}
  • 2.bind server method to client

<script>
    $(document).ready(function () {
        var obj = $.connection.myhub;
        $.connection.hub.start().done(function () {
            obj.server.serverMethod();
        }).fail(function () {
            alert("No Connected");
        });
});
</script>
  • 3.Add a break point to server method and execute the connection

    • It will pause at the break point

Last updated