为什么从角度传递反应形式值在服务器端(.net核心API)获取null?

时间:2018-06-09 16:39:23

标签: angular asp.net-core-2.0 .net-core-angular

我使用了Angular和.net core 2 API。我在Angular中构建了一个反应式表单,并尝试将其发布到API端,但问题是如果我将静态值传递给服务器然后它需要正确,但是当我尝试将表单值传递给API时它会变为空。 我不明白是什么问题。

这是我的组件代码:

private executeClientCreation(clientFormValue) {

  let client1 = {
    "FirstName": "abc",
    "LastName": "xyz",
    "BusinessName": "ABC & Co.",
    "ClientType": "Company",
    "DateOfBirth": "1995-09-16",
    "Status": "Active",
    "CreatedDate": "2018-06-04",
    "Createdby": 1
  };
  let client2: Client = clientFormValue;

  console.log("client1", client1);
  console.log("client2", client2);
  let apiUrl = 'client';
  this.repository.create(apiUrl, client1)
    .subscribe(res => {
        ( < any > $('#successModal')).modal();
      },
      (error => {
        this.errorHandler.handleError(error);
        this.errorMessage = this.errorHandler.errorMessage;
      })
    )
}

  1. 在控制台日志中,您可以看到两个对象相同: enter image description here

  2. 如果我传递client1对象,则工作正常: enter image description here

  3. 不正常工作,意味着如果我传递client2对象,则返回null: enter image description here

  4. typescript接口:

    export interface Client {
      ClientID: number;
      FirstName: string;
      MiddleName: string;
      LastName: string;
      DateOfBirth: Date;
      Gender: string;
      BusinessName: string;
      ClientType: string;
      PANNumber: string;
      AadharNumber: number;
      NameAsPerAadhar: string;
    }

    c#c​​lass:

    [Table("clientmaster")]
    public class Client : BaseClass, IEntity
    {
        public int Id { get; set; }
    
        public string FirstName { get; set; }
    
        public string MiddleName { get; set; }
    
        public string LastName { get; set; }
    
        public string BusinessName { get; set; }
    
        public string ClientType { get; set; }
    
        public string Gender { get; set; }
    
        public DateTime DateOfBirth { get; set; }
    
        public string PANNumber { get; set; }
    
        public long AadharNumber { get; set; }
    
        public string NameAsPerAadhar { get; set; }
    }
    

0 个答案:

没有答案