With Signal R, if trying to send an object, what is the syntax to pass the model?
private async void FormLoaded(object sender, RoutedEventArgs e)
{
//Connection stuff...
Proxy.On("sendHello", () => OnSendDataConnection(ModelBuilder()));
}
private void OnSendDataConnection(ConnectionModel model)
{
Dispatcher.Invoke(DispatcherPriority.Normal,model?????)
this.Dispatcher.Invoke((Action)(LoadW));
}
Looking at the question (text, and not the code) I understand you are trying to send Complex object to JS side and use it there? Is that correct?
In that case the solution is supposed to be simple:
From the ASP.NET.SignalR site:
You can specify a return type and parameters, including complex types and arrays, as you would in any C# method. Any data that you receive in parameters or return to the caller is communicated between the client and the server by using JSON, and SignalR handles the binding of complex objects and arrays of objects automatically.
Example C#:
public void SendMessage(string name, string message)
{
Clients.All.addContosoChatMessageToPage(new ContosoChatMessage() { UserName = name, Message = message });
}
JS:
var contosoChatHubProxy = $.connection.contosoChatHub;
contosoChatHubProxy.client.addMessageToPage = function (message) {
console.log(message.UserName + ' ' + message.Message);
});
Where ContosoChatMessage is:
public class ContosoChatMessage
{
public string UserName { get; set; }
public string Message { get; set; }
}
(read on for examples...)
So basically, in JS once 'model' received, you should be able to use 'model.XY', where XY is a member of the model complex object.
I hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With