简体   繁体   English

将复杂对象从Angular发送到SignalR

[英]Sending Complex Object From Angular to SignalR

I am having trouble sending a complex object to my SignalR hub. 我无法将复杂的对象发送到SignalR集线器。 My JavaScript object matches exactly to my C# object, so I would expect everything to work. 我的JavaScript对象与我的C#对象完全匹配,因此,我希望一切正常。 However, I am unable to hit my UpdateEmployee method. 但是,我无法点击我的UpdateEmployee方法。 I have other methods in my hub that work just fine with simple types. 我的枢纽中还有其他方法可以很好地处理简单类型。 Here is what I currently have implemented - 这是我目前已实现的-

SignalR Hub SignalR集线器

public void UpdateEmployee(int userId, Employee employee)
{
    // Update employee
}

Where Employee is defined as Employee定义为

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 只是简单地继承了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 我试图从我的SignalR JavaScript客户端中找到该方法

$.connection.myHub.server.updateEmployee(userId, employee);

Where my employee object in JavaScript looks like 我的employee对象在JavaScript中的样子

{ Id: 1, FirstName: "Test", LastName: "One", DateOfBirth: "01012001" } 

Is there anything I am doing wrong here? 我在这里做错什么吗?

Have you tried it without the DateOfBirth value? 您是否尝试过没有DateOfBirth值?

Perhaps it isn't able to bind your value 01012001 to the nullable DateTime? 也许它不能将您的值01012001绑定到可为空的DateTime? I have a feeling it has to be either NULL or a bindable value, else the binding will actually fail. 我觉得它必须是NULL或可绑定值,否则绑定实际上将失败。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM