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

  • Home
  • SEARCH
  • 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 6786975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:18:35+00:00 2026-05-26T17:18:35+00:00

I am stuck in a weird situation. I have a controller action which is

  • 0

I am stuck in a weird situation. I have a controller action which is passed a category string. Then the action method matches the string in the database and collects the sub categories and products for it. Now, What I want is to achieve pagination for the products if they are greater than 10. The view is a strongly-typed one for Category Model

Following is the code for action method.

    public ActionResult Catalog(string id)
    {
        Category catalog = pe.Categories.Where(cat => cat.CategoryName == id).Single();
        return View(catalog);
    }

I have done pagination in my other project like following but in that case the collection was an IQueryable which can’t be in the above case since its just for one category. Also, I am already passing an argument in the above function so how can i pass two.

    public ViewResult Index(int? page)
    {
        IQueryable<Album> albums = db.Albums.Include(a => a.Genre).Include(a => a.Artist).OrderBy(a => a.Title);
        int pageIndex = page ?? 1;
        return View(albums.ToPagedList(pageIndex, PageSize));
    }

Please tell me how will you tackle such scenario.

  • 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-26T17:18:36+00:00Added an answer on May 26, 2026 at 5:18 pm

    Use a viewmodel to collect just the information that you want to show in your view. In your selection logic, select into the viewmodel the top-level attributes from the category and the relevant parts of the association. You can certainly have more than one parameter to the method. Supply the extra parameters to the route values in your ActionLink or Form helper methods and it should construct the Url properly to reference your action. Note you will need to change the type of the model in the view as well to match that from the action.

    public ActionResult Catalog(string id, int? page)
    {
        page = page ?? 1;
        var category = pe.Categories.SingleOrDefault(cat => cat.CategoryName == id);
        var model = new CatalogViewModel
                    {
                           ID = category.ID,
                           Name = category.CategoryName,
                           Subcategories = category.Subcategories,
                           Products = category.Products.ToPagedList( page, PageSize )
                    };
    
        return View(model);
    }
    

    View (sample)

    @if (Model.Products.Page < Model.Products.Pages)
    {
        @Html.ActionLink( "Next",
                          "catalog",
                          new { id = Model.ID, page = Model.Products.Page + 1 } ) 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am stuck on a weird problem. I have a CashGameGeneralViewModel class which looks
I'm stuck with a weird problem. I have two files a.c and b.c as
I have a weird question. If I get somehow stuck in my tests, I
I'm stuck with retrieving data from a MySQL-database in an efficient way. I have
I am stuck in weird situation. I want to upload photo from my iPad
I have a weird deadlock situation. After attached visual studio. I saw 3 threads
I have a weird scenario in which the website seems to randomly run out
i have a weird problem where css generated via php (stuck with a weird
Just learning Silverlight 4/RIA and i 'm stuck in a weird problem: setup an
Being stuck with a legacy database schema that no longer reflects your data model

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.