I'm creating an Asp.Net MVC project and found a problem in View. See the code:
<script>
var data = [];
for (var i = 0; i < '@(Model.Count())'; i++) {
data[i] = {
"source": '@(Model.ElementAtOrDefault(0).Source)',
"percentage": '@(Model.ElementAtOrDefault(0).Percentage)'
};
}
</script>
Well, what I need is simple! Instead of passing a fixed index (in case 0), I need to pass the value of i
, but it has been declared in javascript and I can not access it within the expression where I get the value of the model.