views:

128

answers:

1

I have cascading drop down lists in a .net mvc view and am using JQuery onchange to pull the next drop down list using a json response. The problem comes in where iI get a circular reference when trying to serialize the linq to sql response.

I understand why it is happening, its because I have the buyer -> contracts and contract -> buyer relationships which will be circular when serialized.

I am wondering what the recommended solution is. Should I create a new json specific object and map the fields I need for the response?

Is there a way of ignoring the relationships when serializing and just returning this table (i dont need any relationships as its just a drop down list).

+1  A: 

I hit this exact same problem recently and it appears there is no real elegant solution to this short of using something like Json.NET (which I've not tried myself but is supposed to not throw the circular reference error).

The solution I ended up using (for my tiny project) was to set the referenced entity to null prior to serialisation. This could get old very quickly for larger projects which I where Json.NET would come in handy I think.

Reza