相关疑难解决方法(0)

WebAPI多个Put/Post参数

我试图在WebAPI控制器上发布多个参数.一个参数来自URL,另一个参数来自正文.这是网址: /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);
}
Run Code Online (Sandbox Code Playgroud)

正文的内容是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
                        }]
                    }
                }]
            }
        }]
    }
}
Run Code Online (Sandbox Code Playgroud)

知道为什么默认绑定无法绑定到offerPriceParameters我的控制器的参数?它始终设置为null.但是我能够使用the从身体恢复数据DataContractJsonSerializer.

我也尝试使用FromBody参数的属性,但它也不起作用.

.net asp.net-web-api

139
推荐指数
8
解决办法
30万
查看次数

标签 统计

.net ×1

asp.net-web-api ×1