在ASP.NET Web API OData(v4)上使用SPATIAL PROPERTY POST实体的正确方法是什么?
GET上的序列化工作正常,但我在POST中尝试的所有内容都会使模型变为空。
是否支持POST?
提前致谢。
public class PlacesController : ODataController
{
[HttpGet]
[EnableQuery]
public virtual async Task<IHttpActionResult> Get([FromODataUri] string key)
{
var place = new Place()
{
Id = Guid.NewGuid().ToString(),
Location = GeographyPoint.Create(1, 1)
};
return Ok(place);
}
[HttpPost]
[EnableQuery]
public virtual async Task<IHttpActionResult> Post(Place place)
{
if (place == null)
{
return BadRequest();
}
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
return Created(place);
}
}
[DataContract]
public class Place
{
[DataMember]
public string Id
{
get;
set;
}
[DataMember]
public GeographyPoint Location
{
get;
set;
}
}
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.MapHttpAttributeRoutes();
var edmBuilder = new ODataConventionModelBuilder();
edmBuilder.EntitySet<Place>("Places");
var model = edmBuilder.GetEdmModel();
config.MapODataServiceRoute(routeName: "ODataRoute", routePrefix: "api", model: model);
}
}
答案 0 :(得分:0)
阅读下面提到的文章后,似乎有可能。您将需要使用oDataActionParameters类型作为帖子的输入,稍后在您的方法中将其转换为所需类型。 Mehtod签名将如下所示:
public async Task<IHttpActionResult> RateProduct(ODataActionParameters parameters)
查看此link以获取示例并深入了解此