http://localhost:15641/api/Complaints/NewComplaint
User-Agent:Fiddler
Content-Type:application / json
主持人:localhost:15641
内容长度:63
RequestBody { “CostCentre”:“test”,“ComplaintText”:“这是测试投诉” }
WebApi控制器
〔路线( “API /投诉/ NewComplaint”)]
[HttpPost]
public void CreateNewComplaint(BLL.Complaint complaint)
{
//call BLL Create complaint method
}
}
我的对象是空值 我在哪里做错了? 我在控制器上设置断点,投诉对象设置为所有空值 如果我没有传递值投诉对象,则self为null 我怎样才能传递对象
答案 0 :(得分:0)
Web API期望发送给它的数据以这样的方式序列化:
Key1=Value1&Key2=Value2&...
如果您使用的是JavaScript或JQuery,请确保发送一个Object(在您的情况下匹配Bll.Complaint),而不是JSON字符串。如果您向我们提供有关如何执行请求的更多详细信息,我将更新此答案以获取如何进行序列化的示例。