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 3218488
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:32:01+00:00 2026-05-17T15:32:01+00:00

I am building a pagination my mvc project and have follew problem. I did

  • 0

I am building a pagination my mvc project and have follew problem.
I did everything for pagination and now need just pass a page information to view data in view.

I have a user control Pagination:

Pagination.ascx:

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Pagination.ascx.cs"
        Inherits="PIMP.Web.TestForum.Views.Shared.Pagination" %>

    <ul id="pagination-flickr">
        <% if (ViewData.Model.HasPreviousPage)
           { %>
        <li class="previous"><a href="<%=ViewData.PageActionLink.Replace("%7Bpage%7D", (ViewData.PageIndex - 1).ToString())%>">
            « Previous</a></li>
        <% }
           else
           { %>
        <li class="previous-off">« Previous</li>
        <% } %>
        <%for (int page = 1; page <= ViewData.Model.TotalPages; page++)
          {
              if (page == ViewData.Model.PageIndex)
              { %>
        <li class="active">
            <%=page.ToString()%></li>
        <% }
             else
             { %>
        <li><a href="<%=ViewData.PageActionLink.Replace("%7Bpage%7D", page.ToString())%>">
            <%=page.ToString()%></a></li>
        <% }
             }

          if (ViewData.Model.HasNextPage)
          { %>
        <li class="next"><a href="<%=ViewData.PageActionLink.Replace("%7Bpage%7D", (ViewData.PageIndex + 1).ToString())%>">
            Next »</a></li>
        <% }
            else
            { %>
        <li class="next-off">Next »</li>
        <% } %>


    </ul>
    <ul id="pagination-flickr0">


<li><a href="<%=ViewData.PageActionLink.Replace("%7Bpage%7D", page.ToString())%>"></a></li>

    </ul>

Pagination.ascx.cs:

public partial class PaginationViewData
    {
        public int PageIndex { get; set; }
        public int TotalPages { get; set; }
        public int PageSize { get; set; }
        public int TotalCount { get; set; }
        public string PageActionLink { get; set; }
        public bool HasPreviousPage
        {
            get
            {
                return (PageIndex > 1);
            }
        }

        public bool HasNextPage
        {
            get
            {
                return (PageIndex * PageSize) <= TotalCount;
            }
        }
    }

    public partial class Pagination : System.Web.Mvc.ViewUserControl<PaginationViewData>
    {
        public Pagination()
        {

        }
    }

class PagedList.cs:

namespace PIMP.Web.TestForum.DataObject.Forum
{
    public class PagedList<T>: List<T>
    {
        public PagedList(IQueryable<T> source, int index, int pageSize)
        {
            this.TotalCount = source.Count();
            this.PageSize = pageSize;
            this.PageIndex = index;
            this.AddRange(source.Skip((index - 1) * pageSize).Take(pageSize).ToList());

            int pageResult = 0;
            for (int counter = 1; pageResult < this.TotalCount; counter++)
            {
                pageResult = counter * this.PageSize;
                this.TotalPages = counter;
            }
        }


        public PagedList()
        {

        }

        public int TotalPages
        {
            get;
            set;
        }

        public int TotalCount
        {
            get;
            set;
        }

        public int PageIndex
        {
            get;
            set;
        }

        public int PageSize
        {
            get;
            set;
        }

        public bool HasPreviousPage
        {
            get
            {
                return (PageIndex > 1);
            }
        }

        public bool HasNextPage
        {
            get
            {
                return (PageIndex * PageSize) <= TotalCount;
            }
        }
    }

    public static class Pagination
    {
        public static PagedList<T> ToPagedList<T>(this IQueryable<T> source, int index, int pageSize)
        {
            return new PagedList<T>(source, index, pageSize);
        }

        public static PagedList<T> ToPagedList<T>(this IQueryable<T> source, int index)
        {
            return new PagedList<T>(source, index, 10);
        }
    }
}

in View I am doing following:

<% Html.RenderPartial("Pagination", new NISE.Web.TestForum.Views.Shared.PaginationViewData()
      {
          PageIndex = ViewData.Model.PageIndex,
          TotalPages = ViewData.Model.TotalPages,
          PageActionLink = Url.Action("Forum", "Thread", new { id = this.Model.Id, page = "{page}" }),
          TotalCount = ViewData.Model.TotalCount,
          PageSize = ViewData.Model.PageSize
      }, null);%>

I dont know what I should do in my controller.
How can I pass Page Information to the ViewData?
My controller looks like that, can you help me to extend it??

 [HttpGet]
        [ValidateInput(false)]
        public ActionResult Thread(Guid id)
        {
            try
            {
                ThreadModel model = new ThreadModel(id);
                model.IncreaseHitCount();

                PagedList<ListView> list = new PagedList<ListView>();
                list.PageIndex = 0;
                list.PageSize = 0;
                list.TotalCount = 0;
                list.TotalPages = 0;

                return View(model);
            }
            catch (Exception ex)
            {
                bool rethrow = ExceptionHelper.Handle(ex, "Business Logic");
                if (rethrow)
                {
                    throw;
                }
            }

            return View();
        }
  • 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-05-17T15:32:02+00:00Added an answer on May 17, 2026 at 3:32 pm

    Well, I did it like this:

    I created a “view-model” of (my custom) data grid which contains infos about the current page, page size, etc.

    it looks like this:

    using System.Collections.Generic;
    
    public class GridContent<T>
    {
        public IEnumerable<T> Data { get; set; }
        public int PageIndex { get; set; }
        public int TotalPages { get; set; }
        public int TotalItems { get; set; }
    }
    

    in the controller I then return the following:

    return View(new GridContent<Entity>()
                {
                    Data = entityEnumeration, // your actual data
                    PageIndex = pageIndex,
                    TotalItems = totalItems,
                    TotalPages = totalItems / pageSize + 1
                });
    

    and finally on the view

    <%@ Page Title="SomeTitle" Language="C#" Inherits="System.Web.Mvc.ViewPage<GridContent<Entity>>" %>
    

    Now you can access the pagination information as well as the data using the wrapper model / class GridContent.

    Hope this helps.

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

Sidebar

Related Questions

Building a lottery scratch-card app in Java. Have allot of it done, just need
I'm building a site that is a portfolio of projects. I have some pagination
I'm building a string via the following: pagination +='<li>''<a href=/main/?page=%(current_link)s'+link+'>%(current)s</a></li>' % \ {'current_link': current_link,
I am building a Recent Activity page just to give some background. Basically this
I am currently building a site with Expression Engine. I have just put some
Building an inventory system. I have lots of products and each product has three
Building my first SL MVVM application (Silverlight4 RC) and have some issues i don't
Building an iPhone OS application that will allow users to anonymously post information to
The page I am building should display a list of items. Let's say these
building on my last question jQuery getting values from multiple selects together I 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.