zoidbergi zoidbergi - 5 months ago 98
JSON Question

Sending JSON with SignalR

I want to send objects from Javascript to Server using Signalr, but the server side method isn't invoked.

// Model-Class generated by EF5.0
public partial class ttFragen
{
...
public long ID { get; set; }
public Nullable<long> UserID { get; set; }
public string Titel { get; set; }
public string Text { get; set; }
public Nullable<int> ProductID { get; set; }
public Nullable<int> Score { get; set; }
public Nullable<System.DateTime> Date { get; set; }
}

public class Chat : Hub
{

public void Send2(ttFragen frage)
{
...
}

}


Client-Code:

$.connection.hub.start().done(function() {

$("#broadcast").click(function () {
var frage = {
ID: -1,
UserID: -1,
Titel: "titel2",
Text:"testsst",
ProductID: -1,
Score: -1,
Date : null
};

chat.server.Send2(frage); // nothing happens
});

Answer

on Client the function has to start lowercase. So changing the call to:

chat.server.send2(frage);

fixes the problem

Comments