cpoDesign
cpoDesign

Reputation: 9143

Signalr response from client

How do I get the result into my action from my subscribed client?

I have setup hub in my mvc application with signalr with purpose to validate clients between multiple clients providers.

which I am accessing in my controller as:

IHubContext _hubContext = GlobalHost.ConnectionManager.GetHubContext<AmsHub>();

and my mvc action

  public ActionResult Index()
    {
        var result = _hubContext.Clients.All.FindUsers("johny brown");
// how do I access the result?
        return View();
    }

My subscribed client ( I have multiple ) with implementation

 var hubConnection = new HubConnection(hubUrl);
 IHubProxy myHubProxy = hubConnection.CreateHubProxy("AmsHub");


 myHubProxy.On("FindUsers", (name) =>
      {
         var foundRecords = new User()
          {
             FirstName = "Johny",
             LastName = "Brown",
             Email = "[email protected]",
          };
     });

Upvotes: 1

Views: 2115

Answers (1)

T N
T N

Reputation: 406

There is no return values in SignalR (from Client to Server). You can define a FindUsersCallback function and call it at your Client. On Server side you handle this "Signal" and give your View() back.

myHubProxy.On("FindUsers", (name) =  > {
        var foundRecords = new User() {
            FirstName = "Johny",
            LastName = "Brown",
            Email = "[email protected]",
        };

        hubConnection.asmHub.FindUsersCallback(foundRecords);
    });

Upvotes: 1

Related Questions