For example, this list contains an overview of documents and needs to allow paging.
The list is used throughout the website.
Depending on the context where it is used, it needs the data from a different source. For example, it can be used on a ‘group’ page, where it needs to load the documents for the group. And it can be used on an ‘event’ page, where it needs to load the documents for the event.
Both situations can also have different filtering on the documents withing the page.
Should the list not have different datasources, I could easily use Html.RenderAction, and start working from there.
But do I supply the list with documents in the caller, or should the list load the documents, depending on filter/paging/… viewdata?
You could implement the list as a partial view instead of a controller action. Then you can use RenderPartial to render the list and pass in a different list of objects depending on what the list should display.
If you pass in an IEnumerable as a model for example you can implement paging using something like Model.Skip(page * pagesize).Take(pagesize)
updated
Let’s not do paging in the view. It might be a better idea to create a model class that does the paging and is actually testable and pass that into the view to serve up the right page of documents. Of course the view is still responsible for showing pages and linking to other pages.
You could create something like a DocumentPager class that wraps an IEnumerable and that does paging. This would look something like this
You can then pass this into the view and into your partial view that can call the GetPage and NumPages method and property.