I'm guessing this is what you looking for. The code is looking for an object to hold list of container.
I would suggest create couple of Objects
public class Container
{
public string ContainerId { get; set; }
public string ContainerName { get; set; }
}
public class Dispatch
{
public Dispatch()
{
Container = new List<Container>();
}
public List<Container> Container { get; set; }
}
below is an example on how to populate it
var Dispatch = new Dispatch();
foreach (var dispatchItem in packItemRequest.DispatchItems)
{
var propertyDispatch = new Container();
propertyDispatch.ContainerId = containerid.ToString();
propertyDispatch.ContainerName = dispatchItem.Container.ToString()
Dispatch.Container.Add(propertyDispatch);
}
Sample output (if implemented correctly :) ):
{
"Container": [
{
"ContainerId": "123",
"ContainerName": "gdfgfdgfd"
},
{
"ContainerId": "222",
"ContainerName": "jhgj,ljkljl"
}
]
}