3
I am 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 was declared in javascript and I can’t access it inside the expression where I get the model value.
A
"source": '@(Model.ElementAtOrDefault('+i.toString()+').Source)'
did not resolve?– Felipe Avelar
Opa my brother, unfortunately I had already tried, but not sure, because when the parentheses after the arroba is opened, he sees the '+i.toString()+' as a literal string.
– Jedaias Rodrigues