I am having trouble sending a complex object to my SignalR hub. My JavaScript object matches exactly to my C# object, so I would expect everything to work. However, I am unable to hit my UpdateEmployee
method. I have other methods in my hub that work just fine with simple types. Here is what I currently have implemented -
SignalR Hub
public void UpdateEmployee(int userId, Employee employee)
{
// Update employee
}
Where Employee
is defined as
public class Employee: Persistable
{
[DataMember]
public DateTime? DateOfBirth { get; set; }
[DataMember]
public string FirstName { get; set; }
[DataMember]
public string LastName { get; set; }
}
Which just simply inherits Persistable
[DataContract]
public class Persistable
{
[DataMember(Name = "id")]
[JsonProperty(PropertyName = "id")]
public int Id { get; set; }
}
I am trying to hit that method from my SignalR JavaScript client
$.connection.myHub.server.updateEmployee(userId, employee);
Where my employee
object in JavaScript looks like
{ Id: 1, FirstName: "Test", LastName: "One", DateOfBirth: "01012001" }
Is there anything I am doing wrong here?
Have you tried it without the DateOfBirth
value?
Perhaps it isn't able to bind your value 01012001
to the nullable DateTime? I have a feeling it has to be either NULL or a bindable value, else the binding will actually fail.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.