-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
438459d
commit 31c1339
Showing
29 changed files
with
5,216 additions
and
5,216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,99 +1,99 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Web.Mvc; | ||
using MvcPaging.Demo.Models; | ||
|
||
namespace MvcPaging.Demo.Controllers | ||
{ | ||
public class PagingController : Controller | ||
{ | ||
private const int DefaultPageSize = 10; | ||
private IList<Product> allProducts = new List<Product>(); | ||
private readonly string[] allCategories = new string[3] { "Shoes", "Electronics", "Food" }; | ||
|
||
public PagingController() | ||
{ | ||
InitializeProducts(); | ||
} | ||
|
||
private void InitializeProducts() | ||
{ | ||
// Create a list of products. 50% of them are in the Shoes category, 25% in the Electronics | ||
// category and 25% in the Food category. | ||
for (var i = 0; i < 527; i++) | ||
{ | ||
var product = new Product(); | ||
product.Name = "Product " + (i + 1); | ||
var categoryIndex = i % 4; | ||
if (categoryIndex > 2) | ||
{ | ||
categoryIndex = categoryIndex - 3; | ||
} | ||
product.Category = allCategories[categoryIndex]; | ||
allProducts.Add(product); | ||
} | ||
} | ||
|
||
public ActionResult Index(int? page) | ||
{ | ||
int currentPageIndex = page.HasValue ? page.Value - 1 : 0; | ||
return View(this.allProducts.ToPagedList(currentPageIndex, DefaultPageSize)); | ||
} | ||
|
||
public ActionResult CustomPageRouteValueKey(SearchModel search) | ||
{ | ||
int currentPageIndex = search.page.HasValue ? search.page.Value - 1 : 0; | ||
return View(this.allProducts.ToPagedList(currentPageIndex, DefaultPageSize)); | ||
} | ||
|
||
public ActionResult ViewByCategory(string categoryName, int? page) | ||
{ | ||
categoryName = categoryName ?? this.allCategories[0]; | ||
int currentPageIndex = page.HasValue ? page.Value - 1 : 0; | ||
|
||
var productsByCategory = this.allProducts.Where(p => p.Category.Equals(categoryName)).ToPagedList(currentPageIndex, | ||
DefaultPageSize); | ||
ViewBag.CategoryName = new SelectList(this.allCategories, categoryName); | ||
ViewBag.CategoryDisplayName = categoryName; | ||
return View("ProductsByCategory", productsByCategory); | ||
} | ||
|
||
public ActionResult ViewByCategories(string[] categories, int? page) | ||
{ | ||
var model = new ViewByCategoriesViewModel(); | ||
model.Categories = categories ?? new string[0]; | ||
int currentPageIndex = page.HasValue ? page.Value - 1 : 0; | ||
|
||
model.Products = this.allProducts.Where(p => model.Categories.Contains(p.Category)).ToPagedList(currentPageIndex, DefaultPageSize); | ||
model.AvailableCategories = this.allCategories; | ||
return View("ProductsByCategories", model); | ||
} | ||
|
||
public ActionResult IndexAjax() | ||
{ | ||
int currentPageIndex = 0; | ||
var products = this.allProducts.ToPagedList(currentPageIndex, DefaultPageSize); | ||
return View(products); | ||
} | ||
|
||
public ActionResult AjaxPage(int? page) | ||
{ | ||
ViewBag.Title = "Browse all products"; | ||
int currentPageIndex = page.HasValue ? page.Value - 1 : 0; | ||
var products = this.allProducts.ToPagedList(currentPageIndex, DefaultPageSize); | ||
return PartialView("_ProductGrid", products); | ||
} | ||
|
||
public ActionResult Bootstrap(int? page) | ||
{ | ||
int currentPageIndex = page.HasValue ? page.Value - 1 : 0; | ||
return View(this.allProducts.ToPagedList(currentPageIndex, DefaultPageSize)); | ||
} | ||
|
||
public ActionResult Bootstrap3(int? page) | ||
{ | ||
int currentPageIndex = page.HasValue ? page.Value - 1 : 0; | ||
return View(this.allProducts.ToPagedList(currentPageIndex, DefaultPageSize)); | ||
} | ||
} | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Web.Mvc; | ||
using MvcPaging.Demo.Models; | ||
|
||
namespace MvcPaging.Demo.Controllers | ||
{ | ||
public class PagingController : Controller | ||
{ | ||
private const int DefaultPageSize = 10; | ||
private IList<Product> allProducts = new List<Product>(); | ||
private readonly string[] allCategories = new string[3] { "Shoes", "Electronics", "Food" }; | ||
|
||
public PagingController() | ||
{ | ||
InitializeProducts(); | ||
} | ||
|
||
private void InitializeProducts() | ||
{ | ||
// Create a list of products. 50% of them are in the Shoes category, 25% in the Electronics | ||
// category and 25% in the Food category. | ||
for (var i = 0; i < 527; i++) | ||
{ | ||
var product = new Product(); | ||
product.Name = "Product " + (i + 1); | ||
var categoryIndex = i % 4; | ||
if (categoryIndex > 2) | ||
{ | ||
categoryIndex = categoryIndex - 3; | ||
} | ||
product.Category = allCategories[categoryIndex]; | ||
allProducts.Add(product); | ||
} | ||
} | ||
|
||
public ActionResult Index(int? page) | ||
{ | ||
int currentPageIndex = page.HasValue ? page.Value - 1 : 0; | ||
return View(this.allProducts.ToPagedList(currentPageIndex, DefaultPageSize)); | ||
} | ||
|
||
public ActionResult CustomPageRouteValueKey(SearchModel search) | ||
{ | ||
int currentPageIndex = search.page.HasValue ? search.page.Value - 1 : 0; | ||
return View(this.allProducts.ToPagedList(currentPageIndex, DefaultPageSize)); | ||
} | ||
|
||
public ActionResult ViewByCategory(string categoryName, int? page) | ||
{ | ||
categoryName = categoryName ?? this.allCategories[0]; | ||
int currentPageIndex = page.HasValue ? page.Value - 1 : 0; | ||
|
||
var productsByCategory = this.allProducts.Where(p => p.Category.Equals(categoryName)).ToPagedList(currentPageIndex, | ||
DefaultPageSize); | ||
ViewBag.CategoryName = new SelectList(this.allCategories, categoryName); | ||
ViewBag.CategoryDisplayName = categoryName; | ||
return View("ProductsByCategory", productsByCategory); | ||
} | ||
|
||
public ActionResult ViewByCategories(string[] categories, int? page) | ||
{ | ||
var model = new ViewByCategoriesViewModel(); | ||
model.Categories = categories ?? new string[0]; | ||
int currentPageIndex = page.HasValue ? page.Value - 1 : 0; | ||
|
||
model.Products = this.allProducts.Where(p => model.Categories.Contains(p.Category)).ToPagedList(currentPageIndex, DefaultPageSize); | ||
model.AvailableCategories = this.allCategories; | ||
return View("ProductsByCategories", model); | ||
} | ||
|
||
public ActionResult IndexAjax() | ||
{ | ||
int currentPageIndex = 0; | ||
var products = this.allProducts.ToPagedList(currentPageIndex, DefaultPageSize); | ||
return View(products); | ||
} | ||
|
||
public ActionResult AjaxPage(int? page) | ||
{ | ||
ViewBag.Title = "Browse all products"; | ||
int currentPageIndex = page.HasValue ? page.Value - 1 : 0; | ||
var products = this.allProducts.ToPagedList(currentPageIndex, DefaultPageSize); | ||
return PartialView("_ProductGrid", products); | ||
} | ||
|
||
public ActionResult Bootstrap(int? page) | ||
{ | ||
int currentPageIndex = page.HasValue ? page.Value - 1 : 0; | ||
return View(this.allProducts.ToPagedList(currentPageIndex, DefaultPageSize)); | ||
} | ||
|
||
public ActionResult Bootstrap3(int? page) | ||
{ | ||
int currentPageIndex = page.HasValue ? page.Value - 1 : 0; | ||
return View(this.allProducts.ToPagedList(currentPageIndex, DefaultPageSize)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Web; | ||
|
||
namespace MvcPaging.Demo.Models | ||
{ | ||
public class ViewByCategoriesViewModel | ||
{ | ||
public IPagedList<Product> Products { get; set; } | ||
public string[] AvailableCategories { get; set; } | ||
public string[] Categories { get; set; } | ||
} | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Web; | ||
|
||
namespace MvcPaging.Demo.Models | ||
{ | ||
public class ViewByCategoriesViewModel | ||
{ | ||
public IPagedList<Product> Products { get; set; } | ||
public string[] AvailableCategories { get; set; } | ||
public string[] Categories { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
namespace MvcPaging.Demo.Models | ||
{ | ||
public class ViewSourceViewModel | ||
{ | ||
public string RazorCode { get; set; } | ||
public string ControllerCode { get; set; } | ||
} | ||
namespace MvcPaging.Demo.Models | ||
{ | ||
public class ViewSourceViewModel | ||
{ | ||
public string RazorCode { get; set; } | ||
public string ControllerCode { get; set; } | ||
} | ||
} |
Oops, something went wrong.