Reputation: 13
I am developing an application in mvc 4, in which I have a grid.mvc to show some data to users , in which I have a field with a checkbox . The problem is when they make use of paging the value of the checkbox is clean and does not maintain the value true . Any suggestions to solve this problem? Thank you.
Upvotes: 0
Views: 2301
Reputation: 320
I'm not positive, so you'll have to try this out as I have no way of testing it right now, but I'm pretty sure your problem is where you create the checkbox:
@Html.CheckBox("ckbPersona_" + Convert.ToString(p.IdPersona), new {})
Each time your user makes use of paging, the page reloads to pull up the next set of data. So, each time this happens your checkbox is set by the above code. That line of code that I've copied from you isn't setting the checkbox to checked, so by default it will be unchecked. This is why, even if your user has checked the box, it will become unchecked when they page.
What you need to do is set some kind of variable that keeps track of whether or not the box is checked. You need to pass this variable to your view when paging occurs, so that when the new page is loaded, you can either check or not check the box, depending on what the user did on the previous page. When you create your box, the code will be something like this:
@Html.CheckBox("ckbPersona_" + Convert.ToString(p.IdPersona), new { @checked = yourVariableHere })
See this stackoverflow question thread for a helpful discussion of your options in this situation.
Upvotes: 1
Reputation: 13
Thanks for you support, the next is my view
<div class="container-fluid table-responsive">
@Html.Grid(Model).Named("grdParticipantes").Columns(columns =>
{
columns.Add().Titled("Seleccionar").Encoded(false).Sanitized(false).SetWidth(45).RenderValueAs(p => @Html.CheckBox("ckbPersona_" + Convert.ToString(p.IdPersona), new {}));
columns.Add(p => p.NombrePersona).Titled(IdiomaDirectorio.lblParticipante).Sortable(true).Filterable(true);
columns.Add(p => p.Equipo).Titled(IdiomaDirectorio.lblEquipo).Sortable(true).Filterable(true);
}).WithPaging(3).WithMultipleFilters()
</div>
Upvotes: 1