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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:22:23+00:00 2026-05-14T19:22:23+00:00

I have a table that lists users that are registered at my website. The

  • 0

I have a table that lists users that are registered at my website. The page contains a textbox that acts like a filter: as soon as a user types something into the textbox, the table is filtered, so only users are retrieved whose name contains the value of the textbox.

This is done using jquery. It posts to a controller action, which in turn returns some json, which is parsed so the user list is updated. This works great.

Now, this user list must have pagination in it. Pretty simple, only previous and next buttons, which will fetch the previous or next 10 results. These are Ajax.RouteLinks. However, I must of course post the correct pagenumber to the controller action, so it knows which users to retrieve. Herein lies the problem: I don’t know how to do this. Where do I get this value from? I have tried:

  • Setting a ViewData key in the controller, but as I return a Json result, this value is never updated.
  • I tried adding the previous and next pagenumbers in the json result, but then what? The Ajax.RouteLink generates a long link with all sorts of data, I don’t see how I can use jquery to easily modify some parameter in there
  • I tried to generate the link server-side and add that to Json, but I can’t access the ViewContext from the controller, which is needed to instantiate a new AjaxHelper in my action. Or whatever.

If it helps, below is some of the code. As you can see in the jquery code, the correct pagenumbers ARE alerted there. But how to get that into the routelink? Or any other smart way to achieve this? Thanks!

jquery code:

function searchUsers() {
  $.post("/Search/Users", $("#searchUsersForm").serialize(), function(data) {
    $('#searchResultsTable tr').remove();
    $.each(data.Result, function(index, result) {
      $('#searchResultsTable').append('<tr><td>' + result.Username + '</td></tr>');
    });
    if (data.PreviousPageNumber != null)
      alert('previous: ' + data.PreviousPageNumber);
    if (data.NextPageNumber != null) {
      alert('next: ' + data.NextPageNumber);
    }
  }, "json");
}

Html:

<form id="searchUsersForm">
        <input type="text" name="userName" id="userName" onkeyup="searchUsers()" onchange="searchUsers()" />
</form>

<%
Response.Write("<span class='pagingPrevious'>" + Ajax.RouteLink("< previous", "User-List", new { pageNumber = ((int?)ViewData["PreviousPageNumber"]).Value }, new AjaxOptions() { InsertionMode = InsertionMode.Replace, UpdateTargetId = "profilePageInbox" }) + "</span>");

Response.Write("<span class='pagingNext'>" + Ajax.RouteLink("next >", "User-List", new { pageNumber = ((int?)ViewData["NextPageNumber"]).Value }, new AjaxOptions() { InsertionMode = InsertionMode.Replace, UpdateTargetId = "profilePageInbox" }) + "</span>");
%>

Controller:

public ActionResult SearchUsers(string userName)
{
      // fetch data

      ViewData["PreviousPageNumber"] =  userViewModel.PreviousPageNumber; // does not work
      ViewData["NextPageNumber"] = userViewModel.NextPageNumber; // does not work
      return this.Json(userViewModel);
}
  • 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-14T19:22:23+00:00Added an answer on May 14, 2026 at 7:22 pm

    I just had the same problem and found quite a simple solution. After spending more than a day on tinkering with tables and stuff, I downloaded this nice component Telerik Asp.Net MVC Grid.
    Since it didn’t do exactly what i wanted to (live filtering) I wrote a small JQuery plugin to handle this missing feature Gridfilter Plugin

    For filtering with a textbox you’d have to do the following: Find this line in the plugin source

    // Binding the Button events
    
    $('.' + opts.applyButtonClass).click(function () {
        ...
    

    now replace the click part with keyup and there you go.

    I would recommend implementing a minimum of letters as well so that just an “a” wouldn’t get filtered instead the filter gets applied after a specified length like: textbox.val().length > 3

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

Sidebar

Related Questions

I have a volunteers_2009 table that lists all the volunteers and a venues table
I have created a report in SSRS that contains 2 matrices (not tables/lists), each
I have a table that contains tasks and I want to give these an
I have a stored procedure that ideally should be able to accept a list/table
I have a table that got into the db_owner schema, and I need it
I have a table that has redundant data and I'm trying to identify all
I have a table that records a sequence of actions with a field that
I have a table that is created in a DataList in ASP.Net. This table
I have a table that holds information about cities in a game, you can
I have a table that has an insert trigger on it. If I insert

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.