Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
});
like image 955
daniel Avatar asked Jan 21 '13 13:01

daniel


1 Answers

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

chat.server.send2(frage);

fixes the problem

like image 129
daniel Avatar answered Oct 08 '22 12:10

daniel