Angular to .core WebAPI is coming NULL all the properties, Object passing (one property is IFormFile)

  Kiến thức lập trình

I am trying to send Angular OBJ to .core WebAPI obj. All properties are showing null except ID.

WebAPI

public class Book
{
    public int BookID { get; set; }
    public string? ISBNNo { get; set; }
    public string? BookName { get; set; }
    public decimal? Price { get; set; }
    public string? AuthorName { get; set; }
    public string? BookImage { get; set; }
    public string? OperationMode { get; set; }
    public IFormFile? FormFile { get; set; }
}

enter image description here

In Angular ,

Class:
enter image description here
Component:

postdata(angBook: any) {
    if (this.angBook.valid) {
      const UIFormData: Book = this.angBook.value;
      const formFileData = new FormData();
       if (!UIFormData.BookID) {
              UIFormData.OperationMode = "ADD"
              UIFormData.BookID=0;      
            } else {
              UIFormData.OperationMode = "EDIT"
            }

            if (this.file) {
              formFileData.append("file", this.file, this.file.name);
              UIFormData.FormFile=formFileData;              
              UIFormData.BookImage= this.file.name;
            }
            this.dataService.ObjBookAddModify(UIFormData);
    }
  }

Angular Service:

/**** To send Data to DB through Object */
  public ObjBookAddModify(BookParameter: Book) {
    var headers = new HttpHeaders({
      "Content-Type": "application/json; charset=utf-8",
      "Accept": "application/json"
      });
  
    this.httpClient.post<any>(this.baseUrl + '/Books', JSON.stringify(BookParameter),{
      headers: headers})
      .subscribe();
  }

.Net Controller Object is showing all property Null Except BookiD (0).
What did I am wrong? Please suggest me.

LEAVE A COMMENT