2017-05-31 56 views
1

我正在嘗試執行PUT Api調用並傳遞一個對象。 在前端,當我執行API調用前console.log對象,它讀取的值很好...ASP.NET核心控制器PUT參數始終爲空

但是,當它到達.Net Core控制器中的斷點時,該值始終空,不管我嘗試什麼。

角/客戶端

public edit(message) { 
      console.log(message); 
      this.$http.put(`api/causemessage`, message).then((res) => { 
       this.$state.reload(); 
      }); 
     } 

的.Net核心控制器

[HttpPut] 
     public void Put([FromBody] CauseMessage msg) 
     { 
      _service.EditCauseMessage(msg); 
      //TODO : Get the PUT to get the correct data from the client side. Client side "should" be sending the 
      //TODO : correct data already. 
     } 

^味精似乎永遠是零,即使在客戶端API調用之前,日誌顯示它充滿了數據。

開發者工具 - 控制檯登錄

Object {id: 1004, message: "Testing123", messageDate: "Today", causeId: "d5a93ae4-f248-439a-9425-8be7746591fc", $$hashKey: "object:15"} 
$$hashKey 
: 
"object:15" 
causeId 
: 
"d5a93ae4-f248-439a-9425-8be7746591fc" 
id 
: 
1004 
message 
: 
"Testing123" 
messageDate 
: 
"Today" 

如果有人可以幫助我瞭解爲什麼我總是收到一個空值,這將是巨大的。

+0

將內容類型設置爲json,並確保JSON.stringyfy發送時的有效負載 – Nkosi

+0

我最終弄清楚了這一點..我需要使用正確的參數爲了使數據綁定工作的DTO。 –

回答

1

需要確保我有一個正確的數據綁定DTO。 我有5個屬性,而不是從客戶端發送的4個。

對不起!但感謝您的答案!

相關問題