Sunday, March 11, 2012

Problem reading values of custom class objects that are returned in a generic list from a

Hi Alex, the first thing I'd suggest for you to do is to install fiddler, and look at the response from the server to verify if the values returned are empty strings or not. I would guess that you aren't getting the response you are expecting from the server, and are likely getting an array of empty objects. Hopefully that will get you started in the right direction in figuring out what's wrong...

Hope that helps,
-Hao


Hao, thanks for the tip. Fiddler is a really cool tool that I hadn't tried before. I can see that it is returning the JSON data like I think it should. It looks sor tof like this although I've again cut out some of the fields for simplicity:

[{"__type":"Company.Section","Name":"Test 1","Id":574},{"__type":"Company.Section","Name":"Test 2","Id":575}]

I was actually suprised by this, because I was starting to think the problem was that MS Ajax wasn't serializing the list to JSON properly. Now I think it might be more likeley to be a problem with my client-side code.


Problem solved. I'm not sure why, but instead of usingfor (xin result), if I use the following code, it works:

for (var z = 0; z < result.length; z++) {

sb.append(z);

sb.append(

': ');

sb.append(result[z].Name);

sb.append(

'\n');

}

No comments:

Post a Comment