0

I have done this many times, but for some reason, it isn't working this time.

I am compiling a list of object, serializing them to json and returning them to my page to display.

foreach (var rec in results)
        {
            clientsout.Add(new Clients
            {
                Forename = rec.Forename,
                Surname = rec.Surname,
                HouseNameNum = rec.HouseNameNum,
                StreetRoad = rec.StreetRoad,
                Area = rec.Area,
                PostCode = rec.PostCode,
                HomeTel = rec.HomeTel,
                Mobile = rec.Mobile,
                WorkTel = rec.WorkTel,
                EmailAddress = rec.EmailAddress
            });
        }
        var json = JsonConvert.SerializeObject(clientsout);
        return json;

i then have a function in my javascript that 'should' loop through each record and create html based on how many results i get back:

for (var i = 0; i < data.length; i++ ){
        var tr = $('i wont bore you with the html');
            $('#clientstable').append(tr);
    }

for some reason, i cant seem to access the data, it is being returned like:

[{"Id":0,"Forename":"K","Surname":"M","HouseNameNum":"3","StreetRoad":"M Road","Area":"H","PostCode":"Postcode Here","HomeTel":111123456,"Mobile":1111,"WorkTel":1111000,"EmailAddress":"someoney@gmail.com","ClientType":null,"TraderId":null},{"Id":0,"Forename":"Kelly","Surname":"SOmeone","HouseNameNum":"87","StreetRoad":"asdlasdkj","Area":"lkjlk","PostCode":"lkjljk","HomeTel":987987,"Mobile":979879,"WorkTel":987978,"EmailAddress":"987987","ClientType":null,"TraderId":null}]

i would normally access each record in the array by data[i].Forename etc etc

it will probably be really simple, but where have i gone wrong here?

I've used the same methods loads of times

kingtreelo
  • 251
  • 3
  • 15

0 Answers0