AS.NET MVC-loop model data in javascript

442 ワード

Key:razor syntax using @: before the js variable in c# code blockExample:
 var chartData = [];

        @for(int i=0; i < Model.ModuleDetails.Count; i++)
        {
            @: chartData.push(@Html.Raw(Json.Encode(Model.ModuleDetails[i].ChartData.ToArray())));
        }
reference:
http://stackoverflow.com/questions/2002831/asp-net-mvc-how-can-you-loop-through-model-data-in-javascript