I have the following controller:
public ActionResult Grid()
{
schoolEntities db = new schoolEntities();
List<Student> result = db.Students.ToList();
// I can't use pagesizelist here, taken from the view
ViewBag.pageSize = int.Parse(pagesizelist.SelectedValue);
return View(result);
}
and relating view:
...
@Html.DropDownList("Page", new SelectList(new Dictionary<string, int> { { "10", 10 }, { "20", 20 }, { "50", 50 } }, "Key", "Value"), new { id = "pagesizelist" })
<div class="code-cut">
@Html.Grid(Model).Columns(Columns =>
{
Columns.Add(c => c.StudentID).Titled("Id").Filterable(true);
Columns.Add(c => c.LastName).Titled("Last name").Filterable(true);
Columns.Add(c => c.FirstName).Titled("First name").Filterable(true);
Columns.Add(c => c.EnrollmentDate).Titled("Enrollment date").Filterable(true);
Columns.Add()
...
}).WithPaging(ViewBag.pageSize).Sortable(true)
I would like to somehow set the .WithPaging() parameter dynamically according to change in DropDownList.
Wrap the "Page" ddl within a form,
Subscribe to its client-side "onchange". Submit the form there,
Handle the "change size" operation within a separate action method,
Specify a new page size value and reload the entire view:
View:
Controller: