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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:37:57+00:00 2026-05-30T21:37:57+00:00

Basically, I’m using WebGrid and I need to filter the results. The first problem

  • 0

Basically, I’m using WebGrid and I need to filter the results. The first problem I have here is it’s my first time using WebGrid and I was hoping some of you could give me a hand with it… So far, I’ve managed to sort grid results and filter them with Ajax, but, when re-sorting the filtered results, the subset is lost and I go back to the beginning with the full set of results. I know why it’s happening of course, but I don’t figure out how to make it work.

Example:

On my view:

@model IQueryable<Cities>
@section MoreScripts
{
    <script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
}

@using (Ajax.BeginForm(new AjaxOptions { InsertionMode = InsertionMode.Replace,     UpdateTargetId = "GridData"}))
{
    <fieldset>
        <legend>Search Filters</legend>
        <br />
        <div>
            Name
        </div>
        <div>
            @Html.TextBox("Name")
        </div>
        <p>
            <input type="submit" value="Search" />
        </p>
    </fieldset>
}

<div id="GridData">
    @Html.Partial("Grid", Model)
</div>

My Partial View:

@model IQueryable<Cities>

@{
    var grid = new WebGrid<Cities>(null,rowsPerPage: 5, defaultSort: "Nombre", ajaxUpdateContainerId: "GridData");
    grid.Bind(Model, autoSortAndPage: true, rowCount: Model.Count());
    @grid.GetHtml(columns: 
                    grid.Columns(
                                grid.Column("Name", "Name", canSort: true),
                                grid.Column("CreationDate", "Creation Date", canSort: true),
                                grid.Column("Active", "Active", canSort: true, format: @<text><input type="checkbox" disabled="disabled" value="@item.ID" @(item.Active == true ? "Checked" : null) /></text>),
                                                                            grid.Column(format: (item) => Html.ActionLink("Edit", "Edit", new { id = item.Id }, new { @class = "editLink smallCell", @title = "Edit" })),
                                grid.Column(format: (item) => Html.ActionLink("Delete", "Delete", new { id = item.Id }, new { @class = "deleteLink smallCell", @title = "Delete" }))),
                          tableStyle: "webgrid",
                          headerStyle: "webgrid-header",
                          footerStyle: "webgrid-footer",
                          alternatingRowStyle: "webgrid-alternating-row",
                          selectedRowStyle: "webgrid-selected-row",
                          rowStyle: "webgrid-row-style");    
}

And finally what am doing wrong is here, on my controller:

    public ActionResult Index()
    {
        return View(repository.GetAllRecords().OrderByDescending(f => f.CreationDate));
    }

    [HttpPost]
    public ActionResult Index(string name)
    {
        var data = repository.GetAllRecords();

        if(!string.IsNullOrEmpty(name))
            data = data.Where(a => a.Name.Contains(name));

        data = data.OrderByDescending(f => f.CreationDate);

        return PartialView("Grid", data);
    }

I’m also using a class WebGrid : WebGrid as seen here:
http://archive.msdn.microsoft.com/mag201107WebGrid/Release/ProjectReleases.aspx?ReleaseId=5667

So, this actually works fine for filtering, but once you get the filtered results and then try to change the sort order of your narrowed search results, you lose the elements and the ‘name’ parameter’s value because the WebGrid goes agains the first controller action. Probably this is not the best approach, but as I said, I’ve never used WebGrid so I’m willing to learn. Any help would be really appreciated. 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-30T21:37:58+00:00Added an answer on May 30, 2026 at 9:37 pm

    Try to add FormMethod.Post to your form, so the request will go to the second ActionResult. Otherwise, the request is a GET, and goes to the first ActionResult Index() without the parameters.

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

Sidebar

Related Questions

Basically I have some code to check a specific directory to see if an
Basically, I have a JTextPane to hold some text which I wish to style.
Basically, I'm using python to print out some information in the terminal and some
Basically I have this server app I built in vc#, and for some reason
Basically I have some sort of third party software running on Windows 7 which
Basically I would like to have some dictionary that is an abstaction over legacy
Basically I need to create a client and server using only the local network,
Basically I have three pages. -A page with all possible search results for example:
Basically I'm using phpdocx on IIS 7.0 (PHP 5.2.14 FastCGI installed). My problem is
Basically, something better than this: <input type=file name=myfile size=50> First of all, the browse

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.