Thread: PaginatedList
View Single Post
 
Old February 3rd, 2011, 10:27 AM
Olin Olin is offline
Registered User
 
Join Date: Jan 2011
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
Default Default parameter for page

To those of you who had errors with the default parameters using .NET 3.5: try this approach with a nullable int:

Code:
        //
        // GET: /Dinners/
        //      /Dinners/Page/2

        public ActionResult Index(int? page)        {

            const int pageSize = 5;
            if (!page.HasValue) { page = 0; }

            var upcomingDinners = dinnerRepository.FindUpcomingDinners();
            var paginatedDinners = new PaginatedList<Dinner>(upcomingDinners,
                                                             page.Value,
                                                             pageSize);

            return View(paginatedDinners);
        }