Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8562455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:44:02+00:00 2026-06-11T16:44:02+00:00

I am using Troy Goode’s PagedList to provide paging information in my WebApi. His

  • 0

I am using Troy Goode’s PagedList to provide paging information in my WebApi. His package returns an IPagedList that implements IEnumerable but also contains custom properties such as IsLastPage, PageNumber, PageCount, etc.

When you try to return this class from a WebApi controller method (such as the GET), the Enumerable is serialized, but the custom properties are not. So, I thought I would use AutoMapper and write a custom type converter to convert to a class such as this:

public class PagedViewModel<T>
{
    public int FirstItemOnPage { get; set; }
    public bool HasNextPage { get; set; }
    public bool HasPreviousPage { get; set; }
    public bool IsFirstPage { get; set; }
    public bool IsLastPage { get; set; }
    public int LastItemOnPage { get; set; }
    public int PageCount { get; set; }
    public int PageNumber { get; set; }
    public int PageSize { get; set; }
    public int TotalItemCount { get; set; }
    public IEnumerable<T> rows { get; set; }
}

Since I move the Enumerable into a distinct property, the serialization handles it perfectly. So, I sat down and wrote a custom type converter like this:

public class PagedListTypeConverter<T> : ITypeConverter<IPagedList<T>, PagedViewModel<T>>
{
    public PagedViewModel<T> Convert(ResolutionContext context)
    {
        var source = (IPagedList<T>)context.SourceValue;
        return new PagedViewModel<T>()
        {
            FirstItemOnPage = source.FirstItemOnPage,
            HasNextPage = source.HasNextPage,
            HasPreviousPage = source.HasPreviousPage,
            IsFirstPage = source.IsFirstPage,
            IsLastPage = source.IsLastPage,
            LastItemOnPage = source.LastItemOnPage,
            PageCount = source.PageCount,
            PageNumber = source.PageNumber,
            PageSize = source.PageSize,
            TotalItemCount = source.TotalItemCount,
            rows = source
        };
    }
}

And then set it up in my configuration like this:

Mapper.CreateMap<IPagedList<Department>, PagedViewModel<Department>>().ConvertUsing(new PagedListTypeConverter<Department>());

But, when I try to call it like this:

var x = Mapper.Map<IPagedList<Department>, PagedViewModel<Department>>(departments);

I get this error:

Missing type map configuration or unsupported mapping.

Mapping types: IPagedList1 -> PagedViewModel1
PagedList.IPagedList1[[Provision.DomainObjects.Department,
Provision.DomainObjects, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null]] ->
Provision.DomainObjects.PagedViewModel
1[[Provision.DomainObjects.Department,
Provision.DomainObjects, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null]]

Destination path: PagedViewModel`1

Source value:
PagedList.StaticPagedList`1[Provision.DomainObjects.Department]

How can I make this work?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T16:44:03+00:00Added an answer on June 11, 2026 at 4:44 pm

    After pulling my hair out, I finally figured this one out. There isn’t anything at all wrong with the code. It turned out to be a threading issue where the configured mappings were getting cleared out. The code above is the proper way to do what I wanted. I am leaving this here so that I can point another question to it for others who need to do the same thing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im hoping that someone has used the very excellent PagedList from Troy Goode ?
I'm currently using PagedList (https://github.com/TroyGoode/PagedList/) to manage my paging in an ASP.NET MVC application.
I've been playing around with Troy Goode's PagedList http://pagedlist.codeplex.com/ . I was wondering if
Using the WEBDav libraries from Troy Wolf I am using the following query to
I currently have pagination working in my MVC 3 project using the PagedList library
I'm hoping Troy Goode or someone else who has done the same thing can
Using ASP.NET MVC4 I have created a DelegatingHandler in a WebAPI project. I use
Using SSRS 2008 R2 I have a background process that dynamically generates RDL for
Using ASP.NET MVC there are situations (such as form submission) that may require a
Using TortoiseSVN against VisualSVN I delete a source file that I should not have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.