Reply to Comment
Yes I am aware of the Stack Overflow method suggested. The problem is that we are dealing with server side and client side script. The foreach method updates the Client on every call. So if you has 500 rows of data, then you will be persistently updating the client 500 times and as it is a single threaded call, the client will simply stop working until the process is complete. Loading the data into Json in the Server creates a lightweight data object. This is only sent once to the client and the Json object (string) is quickly unpacked in the client allowing a quicker response. I hope that this clears up your concerns.