public ActionResult UserGrid(string pageSize, string page, string sort) { // Convert pageSize and page to integers, setting a default value is they are not convertable int pSize; if (!int.TryParse(pageSize, out pSize)) { pSize = 5; } int p; if (!int.TryParse(page, out p)) { p = 0; } //Get the user collection IEnumerable<User> user = repository.Get(pSize, p, sort); //Construct the viewModel UserGridModel gridModel = new UserGridModel { Users = user, PageSize = pSize, CurrentPage = p, RowCount = repository.Count() }; return PartialView(gridModel); }
public ActionResult UserGrid(string pageSize, string page, string sort) { // TODO: complete this method // Assign Default values to parameters if null. int pSize = (pageSize == null ? 5 : Convert.ToInt32(pageSize)); // The 'page' value passed in is obtained from the page bar at // the bottom of the WebGrid, this is the absolute page number. // However, the repository uses it as a Zero based index number // as does the WebGrid, therefore, we must adjust this absolute // page passed in to match the index. int p = (page == null ? 0 : (Convert.ToInt32(page) - 1)); // get the page of users and the total number of users // from the repository var users = repository.Get(pSize, p, sort); int usersCount = repository.Count(); // Construct the ViewModel for the UserGrid var usersView = new UserGridModel() { Users = users, PageSize = pSize, CurrentPage = p, RowCount = usersCount }; // Return the view model return PartialView(usersView); }