我有一个OData控制器。删除和修补方法工作得很好,但我无法点击Post方法。我是否必须发布整个对象或仅发布密钥好吗?
运行良好的补丁请求:
返回404的Post请求:
我没有发送任何带有帖子请求的正文
控制器:
public class CarouselController : ODataController<CarouselTableDto>
{
private readonly CarouselService _service;
public CarouselController(CarouselService service)
{
_service = service;
}
public class ModelRegistration : ModelRegistration<CarouselTableDto> { }
protected override IQueryable<CarouselTableDto> GetData()
{
return _service.QueryAll();
}
public async Task<IHttpActionResult> Patch([FromODataUri] int key, Delta<CarouselTableDto> data)
{
ChangePassivable(data, active => _service.SetIsActive(key, active));
return StatusCode(HttpStatusCode.NoContent);
}
public async Task<IHttpActionResult> Delete([FromODataUri] int key)
{
_service.Delete(key);
return StatusCode(HttpStatusCode.NoContent);
}
[HttpPost]
public IHttpActionResult Post([FromODataUri] int key)
{
_service.Copy(key);
return StatusCode(HttpStatusCode.NoContent);
}
}
答案 0 :(得分:0)
如果您想发布实体,您应该发布到实体集,例如... / Carousels
和有效负载如:
string payload = @"{
""ID"": 3,
""Name"": ""def""
}";