Pass multiple complex objects to a post/put Web API method

后端 未结 11 1456
南旧
南旧 2020-11-29 21:51

Can some please help me to know how to pass multiple objects from a C# console app to Web API controller as shown below?

using (var httpClient = new System.N         


        
11条回答
  •  情话喂你
    2020-11-29 22:02

    As @djikay mentioned, you cannot pass multiple FromBody parameters.

    One workaround I have is to define a CompositeObject,

    public class CompositeObject
    {
        public Content Content { get; set; }
        public Config Config { get; set; }
    }
    

    and have your WebAPI takes this CompositeObject as the parameter instead.

    public void StartProcessiong([FromBody] CompositeObject composite)
    { ... }
    

提交回复
热议问题