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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:56:58+00:00 2026-06-09T23:56:58+00:00

Html helper @Html.Pager from MvcPaging 2.0. has .Options(o => o.RouteValues(object RouteValues)) which can return

  • 0

Html helper @Html.Pager from MvcPaging 2.0. has .Options(o => o.RouteValues(object RouteValues)) which can return Model back to Controller,but MvcPaging requires this helper to be filled with IPagedList<model> in View that he lives in. This is the Model that generates table and paging. What is the best way to implement mvcpaging 2.0. using SearchModel for search and Model to display results?

Example:

MODELS:

public class SearchModel
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
}

public class Person
{
    [Key]
    public int Id { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public DateTime Dob { get; set; }
    public string City { get; set; }
}

VIEW:
Index.cshtml

@using (Ajax.BeginForm("Search", "SearchPerson", new AjaxOptions
{
    HttpMethod = "GET",
    InsertionMode = InsertionMode.Replace,
    UpdateTargetId = "main_search_result_table_id"
}))
{    
    @Html.TextBoxFor(m => m.FirstName)
    @Html.TextBoxFor(m => m.LastName)
    <input type="submit" value="Search"/>
}
 <div id="main_search_result_table_id">
      @{Html.RenderPartial("_InitPartialEmpty");}
 </div>

_ResultPartial.cshtml

@using MvcPaging
@model IPagedList<Models.Person>

<table>
@foreach (var p in Model)
{
<tr>
    <td>@p.FirstName</td>
    <td>@p.LastName</td>
    <td>@p.Dob</td>
    <td>@p.City</td>
</tr>
}
<table>

 @Html.Pager(Model.PageSize, Model.PageNumber,
                 Model.TotalItemCount,  new AjaxOptions 
 { 
     UpdateTargetId = "main_search_result_table_id"
 }).Options(o => o.RouteValues(Model)) //==> IPagedList<Models.Person>

CONTROLLER

public ActionResult SearchPerson(int? page,SearchModel person)
{
    List<Person> result= adapter.GetPersons(person);

    int currentPageIndex = page.HasValue ? page.Value - 1 : 0;

    return PartialView("_ResultPartial", 
                result.ToPagedList(currentPageIndex, 10, result.Count()));
}

The question is how to implement MvcPaging2.0 using model for search?Or is there another way, a better way, to have complex searches and not using model to transfer data query? Any thoughts?

I am using MvcPaging 2.0. ,docs

EDIT:*

Thanks Darin for answer but I manage to pull it of like this:

*_ResultPartial.cshtml*

@Html.Pager(Model.PageSize, Model.PageNumber,
             Model.TotalItemCount,  new AjaxOptions 
{ 
 UpdateTargetId = "main_search_result_table_id"
 }).Options(o => o.Action("AjaxPaging"))

CONTROLLER

public ActionResult SearchPerson(int? page,SearchModel person)
{
    IQueryable<Person> query= adapter.GetPersons(person);

    Session["SearchQuery"] = query;

    int currentPageIndex = page.HasValue ? page.Value - 1 : 0;

    List<Person> persons = query.ToList();

    return PartialView("_ResultPartial", 
                persons.ToPagedList(currentPageIndex, 10, persons.Count()));
}


public ActionResult AjaxPaging(int? page)
{
    IQueryable<Person> query = Session["SearchQuery"] as IQueryable<Person>;

    int currentPageIndex = page.HasValue ? page.Value - 1 : 0;

    List<Person> persons = query.ToList();

    return PartialView("_ResultPartial", 
                persons.ToPagedList(currentPageIndex, 10, persons.Count()));
}
  • 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-06-09T23:57:00+00:00Added an answer on June 9, 2026 at 11:57 pm

    You could write a custom extension method that will harvest all query string parameters and add them to the page link in addition to all the currentPage, pageNumber, totalItemCount, etc … stuff:

    public static class PagerOptionsBuilderExtensions
    {
        public static PagerOptionsBuilder AddFromQueryString(
            this PagerOptionsBuilder builder, 
            HttpRequestBase request
        )
        {
            foreach (string item in request.QueryString)
            {
                builder.AddRouteValue(item, request.QueryString[item]);
            }
            return builder;
        }
    }
    

    and then:

    .Options(o => o.RouteValues(Model).AddFromQueryString(Request))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've crated a simple helper, which produces a hyperlink from controller's name, action's name
Ive got this function as a html helper which should write a javascript function
I have something like this and it has been created from jQuery .append(html) <div
I have an HTML Helper that essentially renders static content read from HTML files
I'm trying to use the new Html helper extension Serialize() from the furthure assembly..
I have an Html Helper that converts an Enum into a SelectList like so:
I use the following HTML helper to generate check box: <%= Html.CheckBox(DeluxeFeature)%> Now I
I have question about parsing in Html helper : I have sth like: @foreach
I want to use the Html Helper class to build, for example, an Html.ActionLink
I have extended the ASP.NET MVC Html Helper to include my own ValidationImage that

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.