C# 发布的json未反映在对象参数中

C# 发布的json未反映在对象参数中,c#,json,asp.net-mvc,typescript,C#,Json,Asp.net Mvc,Typescript,在我的Web应用程序中,我发布了一个json格式的消息对象,以将其保存到数据库中。通过Firefox中的devtools,我可以看到发布了有效的json,但在调试服务器代码(MVC#)时,Message类型的参数对象的title和body属性为空 typescript中的对象定义: export interface IMessage { title: string; body: string; isHidden: boolean; } 将对象发布到服务器的代码: pub

在我的Web应用程序中,我发布了一个json格式的消息对象,以将其保存到数据库中。通过Firefox中的devtools,我可以看到发布了有效的json,但在调试服务器代码(MVC#)时,Message类型的参数对象的title和body属性为空

typescript中的对象定义:

export interface IMessage {
    title: string;
    body: string;
    isHidden: boolean;
}
将对象发布到服务器的代码:

public postNewMessage(message: IMessage)
{
    return this.http.postJson("/messages/newmessage", message);
}
我看到的发布到Web服务器的json:

{"title":"title","body":"body message","isHidden":true}
服务器代码:

[HttpPost("newmessage")]
public async Task<JsonResult> Post(MessageSummary message)
{
}

因此,当我在服务器端操作上设置断点时,消息对象不是null,但title和body属性是空的。

我以前从未使用过typescript,但body旁边的
不是

export interface IMessage {
    title: string;
    body, string;
    isHidden: boolean;
}

我以前从未使用过typescript,但正文旁边的这个
是否不是

export interface IMessage {
    title: string;
    body, string;
    isHidden: boolean;
}

我明白了这一点,解决方案其实相当简单,只需添加[FromBody],我就得到了发布的对象数据:

[HttpPost("newmessage")]
public async Task<JsonResult> Post([FromBody] MessageSummary message)
{
}
[HttpPost(“newmessage”)]
公共异步任务发布([FromBody]消息摘要消息)
{
}

我明白了这一点,解决方案实际上相当简单,只需添加[FromBody],我就得到了发布的对象数据:

[HttpPost("newmessage")]
public async Task<JsonResult> Post([FromBody] MessageSummary message)
{
}
[HttpPost(“newmessage”)]
公共异步任务发布([FromBody]消息摘要消息)
{
}

这实际上只是我的文章中的一个输入错误,而不是编辑我文章的实际代码。谢谢你指出这一点。这实际上只是我的文章中的一个输入错误,而不是我编辑的文章中的实际代码。谢谢你指出这一点。