jquery AJAX缺少服务器响应中的对象

时间:2016-10-03 09:05:11

标签: jquery ajax asp.net-core-mvc

我对我的控制器进行了基本的ajax调用:

$.ajax({
    url: 'Final/EditCustomer/' + '@Model.CustomerId',
    success: function (data) {
        console.log(data);
    }
});

到目前为止,这工作正常,在我的客户对象中调用控制器操作,包括Tenant对象和CustomerType对象:

public IActionResult EditCustomer(int ID)
{
    var customer = new TCustomer();
    customer = _context.TCustomer
        .Where(c => c.CustomerId == 1)
        .Include(x => x.Tenant)
        .Include(y => y.CustomerType)
        .FirstOrDefault();
    return new ObjectResult(customer);
}

现在这里很奇怪,当我在我的ajax调用中检索对象时,我可以在控制台中看到Customer对象具有包含CustomerType对象的值,但是我没有得到来自服务器的租户对象,即使它告诉我它是从控制器发送的:

修改

TCustomer模型:

    namespace DAL.Entities
    {
    [Table("T_Customer")]
    public partial class TCustomer
    {
    public TCustomer()
    {
        TCustomerDocument = new HashSet<TCustomerDocument>();
        TLinkMgmtNetToCustomer = new HashSet<TLinkMgmtNetToCustomer>();
        TLinkPersonToCustomer = new HashSet<TLinkPersonToCustomer>();
        TLinkSrvAppAcntToCustomer = new HashSet<TLinkSrvAppAcntToCustomer>       ();
        TPersonalAccount = new HashSet<TPersonalAccount>();
        TUserFavoritCustomer = new HashSet<TUserFavoritCustomer>();
    }

    [Column("Customer_ID")]
    [Key]
    public int CustomerId { get; set; }
    //[Required]
    //[MaxLength(250)]
    //public string Customer { get; set; }
    [MaxLength(250)]
    public string Notes { get; set; }
    public string Message { get; set; }
    [Column("Old_SiteID")]
    public int? OldSiteId { get; set; }
    [MaxLength(50)]
    public string ImportQueryName { get; set; }
    [Column(TypeName = "datetime")]
    public DateTime? ImportDate { get; set; }
    [MaxLength(50)]
    public string FirmIndex { get; set; }
    [MaxLength(50)]
    public string BskNumberCustomer { get; set; }
    public bool MaintenanceReasonRequired { get; set; }
    [Column("Tenant_ID")]
    public int TenantId { get; set; }
    [Column("CustomerType_ID")]
    public int CustomerTypeId { get; set; }
    [MaxLength(50)]
    public string UpdateUser { get; set; }
    [Column(TypeName = "datetime")]
    public DateTime? UpdateDate { get; set; }
    [MaxLength(50)]
    public string AddUser { get; set; }
    [Column(TypeName = "datetime")]
    public DateTime? AddDate { get; set; }
    public bool? Recording { get; set; }
    [Column("CH_Location")]
    public bool? ChLocation { get; set; }
    public bool? ProactiveSurveillance { get; set; }

    [InverseProperty("Customer")]
    public virtual ICollection<TCustomerDocument> TCustomerDocument { get; set; }
    [InverseProperty("Customer")]
    public virtual ICollection<TLinkMgmtNetToCustomer> TLinkMgmtNetToCustomer { get; set; }
    [InverseProperty("Customer")]
    public virtual ICollection<TLinkPersonToCustomer> TLinkPersonToCustomer { get; set; }
    [InverseProperty("Customer")]
    public virtual ICollection<TLinkSrvAppAcntToCustomer> TLinkSrvAppAcntToCustomer { get; set; }
    [InverseProperty("Customer")]
    public virtual ICollection<TPersonalAccount> TPersonalAccount { get; set; }
    [InverseProperty("Customer")]
    public virtual ICollection<TUserFavoritCustomer> TUserFavoritCustomer { get; set; }
    [ForeignKey("CustomerTypeId")]
    [InverseProperty("TCustomer")]
    public virtual TCustomerType CustomerType { get; set; }
    [ForeignKey("TenantId")]
    [InverseProperty("TCustomer")]
    public virtual TTenant Tenant { get; set; }

}

}

0 个答案:

没有答案