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"
如果有人可以帮助我了解为什么我总是收到一个空值,这将是巨大的。
将内容类型设置为json,并确保JSON.stringyfy发送时的有效负载 – Nkosi
我最终弄清楚了这一点..我需要使用正确的参数为了使数据绑定工作的DTO。 –