1

i get this in chrome debug picsList.push(BL.datafuncs+pics); a string insted of picsList.push([{img:"",url:""}]); an 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> a = new List<pics>();

                    pics p =new pics();
                    p.img = "", 
                    p.url = "";
                    a.Add(p);

            return a;
        }
2
  • I think razor is using "ToString()" method of "item". Maybe JsonConvert.SerializeObject? Commented May 31, 2015 at 22:16
  • Please, mark as anwser if help ya! tks! =) Commented May 31, 2015 at 22:36

2 Answers 2

1

I think razor is using "ToString()" method of "item".
Maybe JsonConvert.SerializeObject?

;P

Sign up to request clarification or add additional context in comments.

Comments

0

You need to convert object to json, you can try:

@:picsList.push(@Html.Raw(Json.Encode(item)));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.