I have a long db networking call and I want to populate my model in chunks. We are talking about asp.net MVC.
I have a vague idea that each time a new chunk is available I should trigger the model.Bind()
but I don’t know how to do the plumbing between
a) the service which is providing the data in chunks- it’s implemented using the event pattern- each time a new chunk is available an event is triggered, but which event ? It should hold a reference to the model?
b) the data which will be bound to the model ( i suppose it should not be an bind(), but an addition to some collection)
c) if everything is ok in steps a and b, then the changes will be propagated to the view without further a do?
You could use long polling with a hidden iframe and chunked transfer encoding from the server which will spit
<script>tags as data becomes available. In this script tag you could invoke a custom callback javascript function that will take care to format the results.UPDATE:
As requested in the comments section here’s a sample implementation of a long polling technique using a hidden iframe.
Let’s suppose that you have some model:
and that you have a service that returns this model in chunks and notifies the caller that a chunk is available using events:
Now, we could have the following controller:
and the following view:
Now the last part of course is the implementation of the custom action result which will do the chunked transfer: