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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:44:06+00:00 2026-05-19T00:44:06+00:00

I’m not sure if what I’m trying to do makes sense. I am attempting

  • 0

I’m not sure if what I’m trying to do makes sense. I am attempting to make a portable pagination widget to use in asp.net mvc.

The tricky part is that I’m storing an object for route values.

public class PaginatedList<T> : List<T>
{
    public PaginationData PaginationData { get; private set; }

    public PaginatedList(IQueryable<T> source, int pageIndex, int pageSize)
    {
        PaginationData = new PaginationData( source.Count() , pageIndex, pageSize);
        this.AddRange(source.Skip((PaginationData.PageIndex - 1) * PaginationData.PageSize).Take(PaginationData.PageSize));
    }

}

public class PaginationData
{
    ////////////////////////////////////////////
    public object PageRoute { get; set; } //   <-- object for route values
    ////////////////////////////////////////////
    public bool HasPreviousPage { get { return (PageIndex > 1); } }
    public bool HasNextPage { get { return (PageIndex < TotalPages); } }
    public int PageIndex { get; private set; }
    public int PageSize { get; private set; }
    public int TotalCount { get; private set; }
    public int TotalPages { get; private set; }

    public PaginationData(int count, int pageIndex, int pageSize)
    {
        PageIndex = pageIndex;
        PageSize = pageSize;
        TotalCount = count;
        TotalPages = (int)Math.Ceiling(TotalCount / (double)PageSize);
    }
}

So I can then define the base route info at the controller level like this:

        PaginatedList<Member> paginatedMembers = new PaginatedList<Member>(members, page, 2);
        // define base url route
        paginatedMembers.PaginationData.PageRoute = new { controller = "AdminMember", action = "MemberList", keyword = keyword };

This allows me to add values like keyword=keyword for the case where the page links should have additional data.

Then The pagination is displayed with a shared, partial view:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Genesis_0_02.Utilities.PaginationData>" %>

<% if (Model.HasPreviousPage) { %> 
        <%: Html.ActionLink("Previous", ViewContext.RouteData.Values["action"].ToString(), new { page = (Model.PageIndex - 1) })%>

    <% } %> 
    <% for (int i = 1; i <= Model.TotalPages; i++) %>
    <% { %>
            <!--How do I add {page=i} to Model.PageRoute object below?-->
            <%: Html.RouteLink(i.ToString(), Model.PageRoute)%>

    <% } %>

    <% if (Model.HasNextPage) {  %> 
        <%: Html.ActionLink("Next", ViewContext.RouteData.Values["action"].ToString(), new { page = (Model.PageIndex + 1) })%>
    <% } %> 

As you can see… the above partial view is not completed yet. I am specifically working on this line:

            <!--How do I add {page=i} to Model.PageRoute object below?-->
            <%: Html.RouteLink(i.ToString(), Model.PageRoute)%>

Is there a way to do this?

  • 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-19T00:44:07+00:00Added an answer on May 19, 2026 at 12:44 am

    You could revise your PaginationData class to something like the following. Note: I renamed the PageRoute property to RouteValues for consistency with the MVC framework.

    public class PaginationData
    {
        private System.Web.Routing.RouteValueDictionary _RouteValues;
    
        public System.Web.Routing.RouteValueDictionary RouteValues
        {
            get
            {
                if (_RouteValues == null)
                {
                    _RouteValues = new System.Web.Routing.RouteValueDictionary();
                }
                return _RouteValues;
            }
            private set { _RouteValues = value; }
        }
    
        public void SetRouteValues(object routeValues)
        {
            this.RouteValues = new System.Web.Routing.RouteValueDictionary(routeValues);
        }
    
        public bool HasPreviousPage { get { return (PageIndex > 1); } }
        public bool HasNextPage { get { return (PageIndex < TotalPages); } }
        public int PageIndex { get; private set; }
        public int PageSize { get; private set; }
        public int TotalCount { get; private set; }
        public int TotalPages { get; private set; }
    
        public PaginationData(int count, int pageIndex, int pageSize)
        {
            PageIndex = pageIndex;
            PageSize = pageSize;
            TotalCount = count;
            TotalPages = (int)Math.Ceiling(TotalCount / (double)PageSize);
        }
    }
    

    You could then add to the route values by doing the following:

    Model.RouteValues.Add("key", value);
    

    or

    Model.RouteValues["key"] = value;
    

    Alternative Approach using Extension Methods to Merge RouteValueDictionaries

    Below are some extension methods that provide some functionality for RouteValueDictionaries.

    public static class RouteValueExtensions
    {
        public static void Merge(this RouteValueDictionary routeValuesA, object routeValuesB)
        {
            foreach (var entry in new RouteValueDictionary(routeValuesB))
            {
                routeValuesA[entry.Key] = entry.Value;
            }
        }
    
        public static RouteValueDictionary With(this RouteValueDictionary routeValuesA, object routeValuesB)
        {
            routeValuesA.Merge(routeValuesB);
            return routeValuesA;
        }
    
        public static RouteValueDictionary With(this RouteValueDictionary routeValues, params object[] routeValuesToMerge)
        {
            if (routeValues != null)
            {
                for (int i = 0; i < routeValuesToMerge.Length; i++)
                {
                    routeValues.Merge(routeValuesToMerge[i]);
                }
            }
            return routeValues;
        }
    
        public static RouteValueDictionary RouteValues(this HtmlHelper htmlHelper, object routeValues)
        {
            return new RouteValueDictionary(routeValues);
        }
    
        public static RouteValueDictionary RouteValues(this HtmlHelper htmlHelper, object routeValuesA, object routeValuesB)
        {
            return htmlHelper.RouteValues(routeValuesA).With(routeValuesB);
        }
    
        public static RouteValueDictionary RouteValues(this HtmlHelper htmlHelper, params object[] routeValues)
        {
            if (routeValues != null && routeValues.Length > 0)
            {
                var result = htmlHelper.RouteValues(routeValues[0]);
                for (int i = 1; i < routeValues.Length; i++)
                {
                    result.Merge(routeValues[i]);
                }
                return result;
            }
            else
            {
                return new RouteValueDictionary();
            }
        }
    }
    

    In this case, I think you could use them with your original model implementation like this:

    Html.RouteLink(i.ToString(), Html.RouteValues(Model.PageRoute, new { page = i }))
    

    or

    Html.RouteLink(i.ToString(), Html.RouteValues(Model.PageRoute).With(new { page = i }))
    

    The downside is that there is some excessive Reflection and instantiation of new RouteValueDictionary objects going on with this approach.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;

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.