Hey Likhitha,
For the listing of pages, what are you using to retrive the list of New Articles? I mean Episerver Find or getting child items list?
Best way would be, create a View Model (NewsArticleViewModel). Add a List<NewsArticleViewModel>
type property into the View Model for News Page (landing page). This view model (NewsArticleViewModel) will have the ids for pre and next page (Prev/Next).
Now, while you are retrieving your list (in any way), just call a function that will fill this information. You can get the prev/next page ids by traversing the list (let me know if you need help for this).
Now, while rendering the News List on landing page add querystring parameters. (see below)
<a href="@Url.ContentUrl(newsItem.ContentLink)?prev=prevPageId&next=nextPageId">@newsItem.TitleLink</a>
Again, on your NewsArticle Page (detail page), you can easily retrieve the prev/next page with the ids (follow this block post for help).
Let me know if you get stuck.
Thanks, and regards
Praful
I would do similar to Praful says above.
In controller for news article I would use GetChildren() from IContentRepository to get a collection of news articles (or using Find if you have that). You can then filter them and sort them in your preffered way probably using the date of the news article. I would then use a custom viewmodel (NewsArticleViewModel) to store a content reference to previous and next article. You can then render that using the @Url.ContentUrl(article.PreviousLink.ContentLink) or similar.
GetChildren() is cached very effeciently so should be very little performance impact if you don't have 1000's of items.
Next level if you want even more performance would be to create your own NewsService class or similar with a GetNewsArticle(ContentReference currentPage) which also uses Episerver caching in the background to cache the result of that call so you dont have to call GetChildren and traverse the collection more than neccessary. For small and medium sites I would probably skip that though.
There are a couple of different options for caching and most work great. I usually use the ISynchronizedObjectInstanceCache.
Hi,
In my website i've News sections, where in it contains News list page(list of all news artciles) and it navigates to details of each item on selecting particular news item.
Now in news details page i've feature of getting previous and Next news article.Currently redirection from news list to details view happens like
<a href="@Url.ContentUrl(newsItem.ContentLink)">@newsItem.TitleLink</a> in news list page.Can any one help me in finding out efficient way to get Previous and next articles from particular news details page.