There are multiple ways. One common approach is to load all the data and then use a modal to show the detail rather than a full page reload.
Feb 23, 2025
10
Level 1
Best Practice - Next/Previous in list
I have a view with an index list of items, I click on an item in the list to get details of that item.
On the detail view I have "Next Item" and "Previous Item" buttons, to navigate to the next, or previous, item in the list.
I have two controller methods, one to produce the collection of items for the index, and one to produce the details for an item.
The question is: how to get the 'next' and 'previous' items in the detail method without re-querying the database every time, duplicating the query that's just been done in the index method?
Is there a way of 'holding' the collection from the index somehow, and just stepping up and down it?
Please or to participate in this conversation.