0
首先,我有這個問題...的WebAPI的OData v4的操作
WebApi OData v4 ComlexType cannot have an EntityType
...已經想通「這是垃圾,但也許我可以解決它」我想我可能會嘗試告訴那的OData我只是返回一個字符串和JSON序列化對象自己...
這是我想要做的
var acptBatch = Builder.EntityType<ProposedOffer>().Collection.Action("AcceptBatch");
acptBatch.Parameter<bool>("asSingleTransaction");
acptBatch.Parameter<string>("perspective");
acptBatch.ReturnsCollection<ValidationResult<ProposedOffer>>();
[HttpPost]
[ODataRoute("AcceptBatch({asSingleTransaction},{perspective})")]
public async Task<IHttpActionResult> AcceptBatch([FromUri]bool asSingleTransaction, [FromUri]string perspective, [FromBody]ICollection<int> offerIds)
{
try
{
var p = (Perspective)Enum.Parse(typeof(Perspective), perspective);
var result = await Service.AcceptOffers(asSingleTransaction, offerIds, p);
return Ok(result);
}
catch (Exception ex)
{
return await Failed(ex);
}
}
什麼它已經奮戰了一個小時左右已經得到了這麼多...
var acptBatch = Builder.EntityType<ProposedOffer>().Collection.Action("AcceptBatch");
acptBatch.Parameter<bool>("asSingleTransaction");
acptBatch.Parameter<string>("perspective");
[HttpPost]
[ODataRoute("AcceptBatch({asSingleTransaction},{perspective})")]
[Route("ProposedOffer/AcceptBatch({asSingleTransaction},{perspective})")]
public async Task<IHttpActionResult> AcceptBatch([FromUri]bool asSingleTransaction, [FromUri]string perspective)
{
try
{
var offerIds = JsonConvert.DeserializeObject<ICollection<int>>(await Request.Content.ReadAsStringAsync());
var p = (Perspective)Enum.Parse(typeof(Perspective), perspective);
var result = await Service.AcceptOffers(asSingleTransaction, offerIds, p);
return Ok();
}
catch (Exception ex)
{
return await Failed(ex);
}
}
任何人有任何想法如何我可以得到我的結果回到基於客戶端調用JavaScript的代碼? 在這一點上,把Ok()中的任何東西都放回到框架中,無論我如何從初始化模型時聲明它,都可以返回406。