I am trying to implement paging for a list of articles, surprisingly enough I have successfully implemented filtering that returns you a partial view for something similar to this but am struggling with pagination.
Any advice would be great. I should elaborate further with my code below. If there is a beter way to do this please let me know.
My Controller:
public ActionResult RenderEducationCenterCategoryArticleListing()
{
//Get all results
var ArticlePages = CurrentPage.Children.Where(x => x.DocumentTypeAlias == "educationCenterArticle" && x.IsVisible()).OrderByDescending(x => x.CreateDate);
//instantiate a list for returning to partial
var articles = new List<Article>();
//check if is an ajax request
if (Request.IsAjaxRequest())
ArticlePages.Skip(Convert.ToInt32(Convert.ToInt32(ConfigurationManager.AppSettings["resultsPerPage"]))).Take(Convert.ToInt32(ConfigurationManager.AppSettings["resultsPerPage"]));
else
ArticlePages.Take(Convert.ToInt32(Convert.ToInt32(ConfigurationManager.AppSettings["resultsPerPage"])));
//loop through nodes needed for partial only
foreach (var article in ArticlePages)
{
var articleImage = Umbraco.Media(article.GetPropertyValue<int>("articleImage")).Url;
var articleNode = new Article(article.Id, articleImage.ToString(), article.Name.ToString(), article.GetPropertyValue("articleIntro").ToString(), Umbraco.NiceUrl(article.Id).ToString(), article.Parent.Name.ToString(), article.CreateDate);
articles.Add(articleNode);
}
//return the partial with the model of List<Article>
return PartialView(LAYOUT_DIRECTORY + "_EducationCenterCategoryArticleListing.cshtml", articles);
}
public ActionResult RenderEducationCenterCategoryArticlePaging(int? page)
{
var ArticlePages = Umbraco.AssignedContentItem.Children.Where(x => x.DocumentTypeAlias == "educationCenterArticle" && x.IsVisible()).OrderByDescending(x => x.CreateDate);
var pager = new Pager(ArticlePages.Count(), page, 8);
return PartialView(LAYOUT_DIRECTORY + "_EducationCenterCategoryArticlePaging.cshtml", pager);
}
Ajax Paging that Returns you a Partial View
Hi all,
I am trying to implement paging for a list of articles, surprisingly enough I have successfully implemented filtering that returns you a partial view for something similar to this but am struggling with pagination.
Any advice would be great. I should elaborate further with my code below. If there is a beter way to do this please let me know.
My Controller:
My Partials:
My Models:
I basically want to paginate the results partial.
Here's a good example of how to do pagination with ajax
https://codeshare.co.uk/blog/how-to-search-by-document-type-and-property-in-umbraco/
is working on a reply...