I have been traying to pass from a view to the action a object that inside its it have as a property a list of object. It is like:
ModelA =
{
PropertyA,
PropertyB,
List<ModelB>
}
ModelB =
{
Property1,
Property2
}
I tried all work around with AJAX like $.toJSON, $.toDictionary.
Also using [0]ModelB, [1]ModelB to avoid using AJAX.
It doesn't matter how I tried I always received ModelA.ModelB as an empty list. All the other properties are ok.
I'm wating too much time on this....
EDIT: The request is from client to server. Here you have how I'm doing the post (at least one of the way I tried)
var model =
{
Cost: $("#Cost").val(),
Time: $("#Time").val(),
Resources: $("#Resources").val(),
Feedstocks: []
};
$.each($(".selected"), function (index, item) {
model.Feedstocks.push({
ProductID: $("#ProductID").val(),
Scrap: $(this).find(".scrap").val(),
Quantity: $(this).find(".quantity").val()
});
});
$.ajax({
type: 'POST',
url: "Products/AddProcess",
contentType: 'application/json',
data: JSON.stringify(model),
dataType: 'json',
success: function (data) {
if (data.Result) {
window.location.href = "/Products/Details/" + $("#ProductID").val();
}
else {
alert(data.Value);
}
}
})