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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:11:36+00:00 2026-05-20T03:11:36+00:00

Hi I was wondering if anyone con shed some light with a problem that

  • 0

Hi I was wondering if anyone con shed some light with a problem that I´m experiencing when implementing pagedlist code (https://github.com/TroyGoode/PagedList) in my asp.net mvc3 website. This are the details of what I´m trying to do:

I created a Viemodel with this details:

public class ProductViewModelList
{
    public List<Product> ProductBrowse { get; set; }
    public int NumberOfProducts { get; set; } 
    public List<Category> CategoryModel { get; set; } 
}

Then a Controller holding the information that I want to pass to the view:

public ActionResult List(int categoryid, int? page)
{
    const int defaultPageSize = 20;
    int currentPageIndex = page.HasValue ? page.Value - 1 : 0;
    var categoryModel = db.Category.Include("Product").Single(c => c.CategoryId == categoryid);
    var paginatedmodel = categoryModel.Product.ToPagedList(currentPageIndex, defaultPageSize);
    var viewModel = new ProductViewModelList
    {
        ProductBrowse = paginatedmodel.ToList(),
        NumberOfProducts = categoryModel.Product.Count()
    };
return View(viewModel);

Finally the View that starts with:

@inherits System.Web.Mvc.WebViewPage<IPagedList<Social.ViewModels.ProductViewModelList>>
@using Social.Helpers;
@using System.Web.Mvc.Html

and create a foreach with pager in this way:

@foreach (var item in Model)
                {
                    <div class="result">
<div class="info_result"><h2><a>@Html.ActionLink(Html.TruncateText(item.Title, 25), "Details", new { id = item.ProductId })</a></h2><p><a>@Html.ActionLink(Html.TruncateText(item.Description, 180), "Details", new { id = item.ProductId })</a></p<a>@String.Format("{0:dddd, MMMM d, yyyy}", item.CreatedOn)</a></div>

<div class="paginacion">@Html.Pager(Model.PageSize, Model.PageNumber, Model.TotalItemCount)</div>

Information: 1- Im using

@inherits System.Web.Mvc.WebViewPage<IPagedList<Social.ViewModels.ProductViewModelList>>

because I need to pass information from the IPagedList and from the ProductViewModelList to the View.

2- If I pass inherits like <IPagedList<Social.ViewModels.ProductViewModelList> I received complete intellisense for IPagedList properties but for Viewmodels NumberofProducts, ProductBrowse, CategoryModel I only receive their names but not ther properties like ProductBrowse.ProductId as an example.

3- I would like to display a URL of the type:
http://www.domain.com/Controller/List?categoryId=2&page=1

4- I dont know what I have to do in order to include object values for

Html.Pager(Model.PageSize, Model.PageNumber, Model.TotalItemCount, ObjectValues for categoryId=2)

Sorry if this is a mess to understand, I tried my best in order to explain.
thanks in advance.

  • 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-20T03:11:37+00:00Added an answer on May 20, 2026 at 3:11 am

    Instead of:

    @inherits System.Web.Mvc.WebViewPage<IPagedList<Social.ViewModels.ProductViewModelList>>
    

    try:

    @model IPagedList<Social.ViewModels.ProductViewModelList>
    

    Also instead of writing foreach loops in your views you could use a display template. So in your view:

    <div class="result">
        @Html.DisplayForModel()
    </div>
    <div class="paginacion">
        @Html.Pager(Model.PageSize, Model.PageNumber, Model.TotalItemCount)
    </div>
    

    and inside ~/Views/Home/DisplayTemplates/ProductViewModelList.cshtml

    @model Social.ViewModels.ProductViewModelList
    <div class="info_result">
        <h2>
            @Html.ActionLink(
                Html.TruncateText(Model.Title, 25), 
                "Details", 
                new { id = Model.ProductId }
            )
        </h2>
        <p>  
            @Html.ActionLink(
                Html.TruncateText(Model.Description, 180), 
                "Details", 
                new { id = item.ProductId }
            )
        </p>
        <!-- I've modified this to use a display template instead of String.Format
        Now you only need to decorate your view model property with the DisplayFormat attribute like this:
        [DisplayFormat(DataFormatString = "{0:dddd, MMMM d, yyyy}")]
        public DateTime? CreatedOn { get; set; }
        -->
        @Html.DisplayFor(x => x.CreatedOn)
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Wondering if anyone out there can shed some light on why the following regular
Wondering if anyone can shed some light on how to create a semi-transparent Help
wondering if anyone has some quick links to code snippets to generate a random
Wondering if anyone can suggest a good file replication tool that will replicate across
Just wondering if anyone has some good resources for learning how to create new
Just wondering if anyone else has spotted this: On some user's machines running our
Wondering if anyone has played around with GitHub's new support for SVN? Would really
Wondering if anyone can assist.. I am adding some jquery to my site, but
Wondering if anyone can help with this. I have a table with some fixed
Im wondering if anyone else has come across this problem when designing websites. Basically

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.