Passing complex type containing array of complex types to Web API

前端 未结 1 1215
野性不改
野性不改 2020-12-10 09:01

Extending on from this question, I\'m trying to pass a complex object containing a collection of complex objects to an ASP.NET Web API controller action method, but I\'m hav

1条回答
  •  有刺的猬
    2020-12-10 09:15

    Until now, no built-in Web API model binders including derived FromUri and FromBody attributes support passing a complex object that contains any property of non-primitive class types (excluding the System.String) with query strings. I had the similar issues and have created a unique and advanced custom model binder, the FieldValueModelBinder class, to work on a target object hierarchy having generic list or array collections. I can use the pure query string type of source data without imbedding any JSON or XML structure into it. The model binder can be used as easy as the FromUri and FromBody attributes. It also works effectively for transferring query string data in both URI and request body.

    Please read my article and download source code I have just posted using this link. You can also run the test app from the download source for your input string, model, and results. I hope that this is the right solution you need.

    0 讨论(0)
提交回复
热议问题