I have these Models.
public class ModelA
{
List<ModelB> ModelB {get;set;}
}
public class ModelB
{
List<ModelC> ModelC {get;set}
}
Now, I tried to convert in my script the models above base from this answer in my view.
<script>
var modelB = '@Html.Raw(Json.Encode(Model.ModelB))';
var modelBData = JSON.parse(modelB);
// Here comes the problem...
var modelC = '@Html.Raw(Json.Encode(Model.ModelB.ModelC))';
</script>
I can convert the Model B to javascript array but failed to convert ModelC into a javascript array. Now, how can I convert the list of ModelC in ModelB into a javascript array? I was hoping someone might be able to spot where i'm going wrong.
ModelAcontained threeModelBitems. The firstModelBcontains oneModelC. The secondModelBcontains twoModelC. The third contains three. How manyModelCitems are you expecting to see in yourHere comes the problemJSON?modelBandmodelBDatalines? (after commenting outvar modelCand other lines that don't compile)