Why getting null on server side(.net core API) from angular passing reactive form value?

359 Views Asked by At

I used Angular and .net core 2 API. I built one reactive form in Angular and try to POST it to API side but here the problem is if I pass static value to server then it take properly but when I tried to pass form value to API then it got null. I don't understand what is the problem.

Here is my component code:

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. In Console log you can see both object is same: enter image description here

  2. Working fine if I pass client1 object: enter image description here

  3. Not working fine, means getting null if I pass client2 object: enter image description here

typescript interface:

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# class:

[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

There are 0 best solutions below