2.2.5.Passing parameters to server method from client

  • 1.Modify the server method: add a string parameter

[HubName("myhub")]
public class MyHub:Hub
{
    public string serverMethod(string msg)
    {
        return msg + " good morning";
    }
    public MyHub()
    {
        //
        // TODO: Add constructor logic here
        //
    }
}
  • 2.Modify html file: alert the string from the server

    • If method works it will go to done()

      <script>
      $(document).ready(function () {
        var obj = $.connection.myhub;
        $.connection.hub.start().done(function () {
            obj.server.serverMethod("Hi").done(function (data) {
                alert(data);
            });
        }).fail(function () {
            alert("No Connected");
        });
      });
      </script>

Last updated