Q:

JavaScript literal insert vaule? (Too many characters in character literal)

Ok so in my mvc View my "Model" is a list of objects and in this case i want to get a specific Id of one of the objects. 
var counter = 0; //for example

var id = '<%=Model[' + counter + '].Id %>';

This is what i get : 
Compiler Error Message: CS1012: Too many characters in character literal

Thanks!

A:

Yes, the counter variable can't be used as the index for Model[], because it only exists on the client (assuming this snippet was inside of a script html element).  When you are creating a view, it might be useful to think of it as a long 'string' that you are constructing (the html returned to the browser).  In this case 'counter' is just some characters in your script block that will eventually be interpreted by the browser, so it's not a variable that can be used while building the view. The <%= %> block just returns a string to append (that's what the = sign does).
Perhaps you intended to have the counter variable in it's own C# code block like so:
<% var counter = 0; %>
<script language=javascript>
  var id = '<%=Model[counter].Id %>';
</script>

