javascript - Add Object from razor to js list not working -


i in chrome debug picslist.push(bl.datafuncs+pics); string insted of picslist.push([{img:"",url:""}]); object

<script>  var picslist = [];      @foreach (var item in bl.datafuncs.getmainpagepics())         {              @:picslist.push(@item);         } </script>    public class pics         {             public string img { get; set; }             public string url { get; set; }         }          public static list<pics> getmainpagepics()         {             list<pics> = new list<pics>();                      pics p =new pics();                     p.img = "",                      p.url = "";                     a.add(p);              return a;         } 

you need convert object json, can try:

@:picslist.push(@html.raw(json.encode(item))); 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -