Accessing the ViewBag list via Javascript

0

I'm trying to access the elements of a list stored in the ViewBag as follows:

function equipamentoTemControle() {

   for(i = 0; i < @ViewBag.qtdEquipamentos; i++) {

      var contratocod = @ViewBag.DadosEquipamentos[i].contratocod;
   }

}

However, when trying to access the contractcod attribute of the i exist. How should I access?

    
asked by anonymous 09.09.2016 / 16:26

1 answer

0

Resolved.

var jsonObj = @Html.Raw(Json.Encode(ViewBag.DadosEquipamentos));

for(i = 0; i < jsonObj.length; i++) {

    var contratocod = jsonObj[i].contratocod;
}
    
09.09.2016 / 17:46