Jacob Jacob - 10 months ago 62
C# Question

Passing object parameter to hub method

Although there are many questions like that on the web, I haven't found a right one that solves my issue:

I have a SignalR hub method:

public ClientResponses ProcessRequest(ClientRequest request) {...}

This method gets
object as parameter:

public class ClientRequest : BaseClientRequest
public string Input { get; set; }

I call this method from the client like that:

var input = new Input(message);
var jsonInput = JSON.stringify(input);

When sending, their values are:

enter image description here

But the method at the server side (
) never called.

When I change this method to get a string type parameter and sent a pure string from the client it works properly.

Answer Source

The short answer is that the line :

var jsonInput = JSON.stringify(input); 

isn't needed as you can send straight javascript objects to SignalR.