此 OData 函数不会反序列化主体中的模型参数。null
从响应中可以看出,它会反序列化。OData V4 中是否支持 FromBody 参数?
ConfigV1.cs
builder.Function("CreateTestModel").Returns<TestModel>();
var edmModel = builder.GetEdmModel()
config.MapODataServiceRoute("ODataRouteV1", "v1", edmModel);
测试控制器.cs
using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.OData;
using System.Web.OData.Query;
using System.Web.OData.Routing;
public class TestController : ODataController
[HttpPost]
[ODataRoute("CreateTestModel")]
public TestModel CreateTestModel([FromBody]TestModel model)
{
return model;
}
}
测试模型.cs
public class TestModel
{
public string Value { get; set; }
}
要求
POST /v1/CreateTestModel HTTP/1.1
Host: localhost:8090
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: 4810cdc0-d92b-b7b5-4328-8b87e0222854
{
"Value": "test"
}
回复
{
"@odata.context":"http://localhost:8090/V1/$metadata#Edm.Null","@odata.null":true
}