Yes, the counter variable cannot be used as an index for Model [], since it exists only on the client (if this fragment was inside the html script element). When you create a view, it may be useful to think of it as a long string that you create (html returns to the browser). In this case, the βcounterβ is just a few characters in your script block that will ultimately be interpreted by the browser, so this is not a variable that can be used to build the view. The <% =%> block simply returns the string to add (which makes the = sign).
Perhaps you intended to have a counter variable in your own C # code block as follows:
<% var counter = 0; %> <script language=javascript> var id = '<%=Model[counter].Id %>'; </script>
source share