我試圖在WebAPI控制器上發(fā)布多個(gè)參數(shù)。一個(gè)參數(shù)來自URL,另一個(gè)參數(shù)來自正文。這是網(wǎng)址: /offers/40D5E19D-0CD5-4FBD-92F8-43FDBB475333/prices/這是我的控制器代碼:public HttpResponseMessage Put(Guid offerId, OfferPriceParameters offerPriceParameters){ //What!? var ser = new DataContractJsonSerializer(typeof(OfferPriceParameters)); HttpContext.Current.Request.InputStream.Position = 0; var what = ser.ReadObject(HttpContext.Current.Request.InputStream); return new HttpResponseMessage(HttpStatusCode.Created);}正文的內(nèi)容是JSON:{ "Associations": { "list": [ { "FromEntityId":"276774bb-9bd9-4bbd-a7e7-6ed3d69f196f", "ToEntityId":"ed0d2616-f707-446b-9e40-b77b94fb7d2b", "Types": { "list":[ { "BillingCommitment":5, "BillingCycle":5, "Prices": { "list":[ { "CurrencyId":"274d24c9-7d0b-40ea-a936-e800d74ead53", "RecurringFee":4, "SetupFee":5 }] } }] } }] }}知道為什么默認(rèn)綁定無法綁定到offerPriceParameters我的控制器的參數(shù)?它始終設(shè)置為null。但是我能夠使用the從身體恢復(fù)數(shù)據(jù)DataContractJsonSerializer。我也嘗試使用FromBody參數(shù)的屬性,但它也不起作用。
3 回答

慕標(biāo)琳琳
TA貢獻(xiàn)1830條經(jīng)驗(yàn) 獲得超9個(gè)贊
如果正在使用屬性路由,則可以使用[FromUri]和[FromBody]屬性。
例:
[HttpPost()]
[Route("api/products/{id:int}")]
public HttpResponseMessage AddProduct([FromUri()] int id, [FromBody()] Product product)
{
// Add product
}
- 3 回答
- 0 關(guān)注
- 1254 瀏覽
添加回答
舉報(bào)
0/150
提交
取消