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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:55:49+00:00 2026-05-13T15:55:49+00:00

I’ve read several different posts on paging w/ in MVC but none describe a

  • 0

I’ve read several different posts on paging w/ in MVC but none describe a scenario where I have something like a search form and then want to display the results of the search criteria (with paging) beneath the form once the user clicks submit.

My problem is that, the paging solution I’m using will create <a href=”…”> links that will pass the desired page like so: http://mysite.com/search/2/ and while that’s all fine and dandy, I don’t have the results of the query being sent to the db in memory or anything so I need to query the DB again.

If the results are handled by the POST controller action for /Search and the first page of the data is rendered as such, how do I get the same results (based on the form criteria specified by the user) when the user clicks to move to page 2?

Some javascript voodoo? Leverage Session State? Make my GET controller action have the same variables expected by the search criteria (but optional), when the GET action is called, instantiate a FormCollection instance, populate it and pass it to the POST action method (there-by satisfying DRY)?

Can someone point me in the right direction for this scenario or provide examples that have been implemented in the past? Thanks!

  • 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-13T15:55:49+00:00Added an answer on May 13, 2026 at 3:55 pm

    My method is to have an Action that handles both the post and the get scenarios.

    This is my which can be handled by both GET and POST methods:

    public ViewResult Index([DefaultValue(1)] int page,
                            [DefaultValue(30)] int pageSize,
                            string search,
                            [DefaultValue(0)] int regionId,
                            [DefaultValue(0)] int eventTypeId,
                            DateTime? from,
                            DateTime? to)
    {
        var events = EventRepo.GetFilteredEvents(page, pageSize, search, regionId, eventTypeId, from, to);
        var eventFilterForm = EventService.GetEventFilterForm(from, to);
    
        var eventIndexModel = new EventIndexModel(events, eventFilterForm);
    
        return View("Index", eventIndexModel);
    }
    

    The eventFilterForm is a presentation model that contains some IEnumerable<SelectListItem> properties for my search form.

    The eventIndexModel is a presentation model that combines the eventFilterForm and the results of the search – events

    The events is a special type of IPagedList. You can get more information and code for that here and here. The first link talks about IPagedList where as the second link has an Advanced Paging scenario which you should need.

    The advanced paging has the following method that I use:

    public static string Pager(this HtmlHelper htmlHelper, int pageSize, int currentPage, int totalItemCount, RouteValueDictionary valuesDictionary)
    

    And I use it like so:

    <%= Html.Pager(Model.Events.PageSize,
                   Model.Events.PageNumber,
                   Model.Events.TotalItemCount,
                   new
                   {
                       action = "index",
                       controller = "search",
                       search = ViewData.EvalWithModelState("Search"),
                       regionId = ViewData.EvalWithModelState("RegionId"),
                       eventTypeId = ViewData.EvalWithModelState("EventTypeId"),
                       from = ViewData.EvalDateWithModelState("From"),
                       to = ViewData.EvalDateWithModelState("To")
                   }) %>
    

    This creates links that look like:

    /event/search?regionId=4&eventTypeId=39&from=2009/09/01&to=2010/08/31&page=3

    HTHs,
    Charles

    Ps. EvalWithModelState is below:

    PPs. If you are going to put dates into get variables – I would recommend reading my blog post on it… 🙂

    /// <summary>
    /// Will get the specified key from ViewData. It will first look in ModelState
    /// and if it's not found in there, it'll call ViewData.Eval(string key)
    /// </summary>
    /// <param name="viewData">ViewDataDictionary object</param>
    /// <param name="key">Key to search the dictionary</param>
    /// <returns>Value in ModelState if it finds one or calls ViewData.Eval()</returns>
    public static string EvalWithModelState(this ViewDataDictionary viewData, string key)
    {
        if (viewData.ModelState.ContainsKey(key))
            return viewData.ModelState[key].Value.AttemptedValue;
    
        return (viewData.Eval(key) != null) ? viewData.Eval(key).ToString() : string.Empty;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 309k
  • Answers 309k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Just pass a List along with that method. Untested pseudo-ish… May 13, 2026 at 9:57 pm
  • Editorial Team
    Editorial Team added an answer Bob has Alice's public key also, and Alice signed the… May 13, 2026 at 9:57 pm
  • Editorial Team
    Editorial Team added an answer Make a server-side XHR request, grab the content, and include… May 13, 2026 at 9:57 pm

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into
I have text I am displaying in SIlverlight that is coming from a CMS

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.