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
Post a Comment