0

I've got a MVC site/view that shows a series of checkboxes across the top that correspond to the years available in the in my webgrid records. I would like to click on the checkboxes to filter the data in the webgrid. I have that working but when I click on the headings in the webgrid to sort it my checkboxes reset back to unchecked.

I am used to webform programming so have always relied on viewstate to maintain the selections.

How do I do this in the MVC world?

Here is my code to display the checkboxes in the view:

  @using (Ajax.BeginForm(new AjaxOptions { InsertionMode=InsertionMode.Replace,UpdateTargetId="myGrid"}))
{
    foreach (var y in Model.Years)
    {
      <input type="checkbox" name="cbYears" value="@y.Value" />
      <label for="cbYears">@y.Value</label>
    }
<br />
<input type="submit" value="Filter Results" />
}

The grid is displayed in a partial view.

TIA

0

2 Answers 2

1

Glad if these could help!

MVC3 WebGrid Page/Sort Issue with a CheckBox elsewhere on the page

http://websitesorcery.com/post/2012/03/19/CheckBox-Issue-with-MVC-3-WebGrid-Paging-Sorting.aspx

Sign up to request clarification or add additional context in comments.

2 Comments

The second link in your answer appears to either be down or possibly dead.
@MattD: thanks for the update. Yes, the website itself "websitesorcery.com" seems to be down.
1

How do I do this in the MVC world?

You have to send the filtering option in the request when you perform sorting in the grid. The idea is whenever you are performing sorting you have to submit the current filter option, current pagination and the other things related to the grid in the request either in query-string or form and in this way you don't need to maintain the state because all the information needed are available in the request.

For ex. if you see jqgrid it provides many options like sorting, filtering, pagination, grouping etc. Say first I've filtered the grid for a particular column/value then if I do sorting then the grid append the current filtered column/value and the sorting column everything as query-strings in the request and so in the server side I don't need to keep any state because all are available in the querystrings.

You also follow a similar kind of approach.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.