LP13
LP13

Reputation: 34109

How to post List of Dictionary

I have a client ( in this case POSTMAN) that is posting collection of object. The properties of the object are not known in advance so I cannot use concrete C# model.

So I am using Dictionary<string,object> that represent a single object where Key will be the property name and Value will be the value of the property. Since client is posting collection i am using List<Dictionary<string,object>>

ISSUE

In controller's action method each dictionary has Key however corresponding value is NULL

POSTMAN

enter image description here

Fiddler shows

model%5B0%5D.FirstName=foo&model%5B0%5D.LastName=bar&model%5B1%5D.FirstName=james&model%5B1%5D.LastName=smith

Quick watch in model:

enter image description here

I tried using JObject, ExpandoObject as model with no luck

Upvotes: 0

Views: 1380

Answers (1)

LP13
LP13

Reputation: 34109

I changed the model type from List<Dictionary<string, object>> to List<Dictionary<string, string>> and it worked

    [HttpPost]
    public IActionResult Update([FromForm]List<Dictionary<string, string>> model)
    {
        return Ok();
    }

Upvotes: 1

Related Questions