jquery - Using c# code in javascript -


i trying use c# in javascript using in mvc razor view using @ sign,

like suppose array name list passed view can access in view like:

view

     length of array :  <input type="text"  value="@model.list.length" />                    or can iterate list array like:           @for(int i=0; i< model.list.length; i++)          {              console.log(model.list[i]);          } 

but question how can iterate or use array in javascript code , similar :

js

      for(var i=0; i<@model.list.length; i++)       {         $("body").append("<h1></h1>").html(@model.list[i]);       } 

thanks !

as posted in comment, bit tricky. however, can try construct javascript object c#.

something (i don't know how works exactly...):

var array = [    @for(var = 0; < model.list.length-1; i++){  @model.list[i] , }    @model.list[length] ] 

which should result in:

var array = [          val1,          val2,          val3,          valn ]  

now have js var array, can work in entire document.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -