I am using an MVC3 Webgrid to display some data, and have applied server side paging/sorting. I also have a checkbox column in the grid. My problem is that when I change pages, I am losing the selected records. I am able to store the selected row IDs in a session variable, but am unable to retrieve the values from the session and bind to the checkboxes in the Webgrid.
Can someone throw some light on this issue? Please also let me know if there is any other/better approach.
Thanks in advance.
Here is a small sample project showing how I've done it. It's based on different answers I've found mostly on Stack Overflow.
The trick is to use
@Html.Raw
and only emit thechecked
attribute when the item is selected. Settingchecked="false"
won't work!HomeController.cs:
Index.cshtml:
Player.cs: