【发布时间】:2017-08-04 19:10:34
【问题描述】:
在我的 web 应用程序中,我以 json 格式发布消息对象以将其保存到数据库中。使用 Firefox 中的 devtools,我可以看到有效的 json 被发布,但是在调试服务器代码(MVC c#)时,Message 类型的参数对象有一个空的 title 和 body 属性。
打字稿中的对象定义:
export interface IMessage {
title: string;
body: string;
isHidden: boolean;
}
将对象发布到服务器的代码:
public postNewMessage(message: IMessage)
{
return this.http.postJson("/messages/newmessage", message);
}
我看到的 json 发布到网络服务器:
{"title":"title","body":"body message","isHidden":true}
服务器代码:
[HttpPost("newmessage")]
public async Task<JsonResult> Post(MessageSummary message)
{
}
Message的C#类定义
public class MessageSummary
{
public long Id { get; set; }
public string title { get; set; }
public string body { get; set; }
public author author { get; set; }
}
所以当我在服务器端设置断点时,消息对象不为空,但标题和正文属性为空。
【问题讨论】:
标签: c# json asp.net-mvc typescript