0
我正在使用web-api控制器。我建立了一个DTO来保存一个Note。为什么我的一些值没有被webapi填充
public class NoteContainer
{
public long? NoteId { get; set; }
public string Type { get; set; }
public string NoteText { get; set; }
public NoteContainer(Note note, string type = null)
{
NoteId = note.Id;
NoteText = note.NoteText;
Type = type;
}
}
我有我的控制器的方法:将NoteContainer从它的所有值的客户端发送
[HttpPost]
public void EditNote(NoteContainer container)
{
//do work here
}
之前。当它到达服务器时,输入为null!我不应该使用一个名为type的变量吗?为什么我失去了价值?
使用邮差我送这个JSON:
{
"noteId": 10,
"type": "person",
"noteText": "loves broccoli",
}
显示您要发送的JSON。我的猜测是它具有小写的“类型”而不是“类型”。 –
'ModelBinder'中有些东西正在被打破。你是否在你的表单组件中输入了'name'属性(例如'') –
试试这个: { “NoteId”:10, “Type” “person”, “NoteText”:“喜欢西兰花”, } – peinearydevelopment