-
-
Notifications
You must be signed in to change notification settings - Fork 216
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
Showing
32 changed files
with
2,791 additions
and
2,824 deletions.
There are no files selected for viewing
7 changes: 3 additions & 4 deletions
7
examples/X.PagedList.Mvc.Example.Core/Controllers/Bootstrap41Controller.cs
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,7 +1,6 @@ | ||
namespace X.PagedList.Mvc.Example.Core.Controllers | ||
namespace X.PagedList.Mvc.Example.Core.Controllers; | ||
|
||
public class Bootstrap41Controller : HomeController | ||
{ | ||
public class Bootstrap41Controller : HomeController | ||
{ | ||
|
||
} | ||
} |
107 changes: 53 additions & 54 deletions
107
examples/X.PagedList.Mvc.Example.Core/Controllers/HomeController.cs
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,61 +1,60 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using System.Collections.Generic; | ||
|
||
namespace X.PagedList.Mvc.Example.Core.Controllers | ||
namespace X.PagedList.Mvc.Example.Core.Controllers; | ||
|
||
public class HomeController : Controller | ||
{ | ||
public class HomeController : Controller | ||
public IActionResult Index(int page = 1) | ||
{ | ||
ViewBag.Names = GetPagedNames(page); | ||
return View(); | ||
} | ||
|
||
public IActionResult AjaxIndex(int page = 1) | ||
{ | ||
var listPaged = GetPagedNames(page); | ||
ViewBag.Names = listPaged; | ||
return View(); | ||
} | ||
|
||
public IActionResult GetOnePageOfNames(int page = 1) | ||
{ | ||
var listPaged = GetPagedNames(page); | ||
ViewBag.Names = listPaged; | ||
return PartialView("_NameListPartial", ViewBag.Names); | ||
} | ||
|
||
public IActionResult Error() | ||
{ | ||
return View(); | ||
} | ||
|
||
protected IPagedList<string> GetPagedNames(int? page) | ||
{ | ||
// return a 404 if user browses to before the first page | ||
if (page.HasValue && page < 1) | ||
return null; | ||
|
||
// retrieve list from database/whereverand | ||
var listUnpaged = GetStuffFromDatabase(); | ||
|
||
// page the list | ||
const int pageSize = 20; | ||
var listPaged = listUnpaged.ToPagedList(page ?? 1, pageSize); | ||
|
||
// return a 404 if user browses to pages beyond last page. special case first page if no items exist | ||
if (listPaged.PageNumber != 1 && page.HasValue && page > listPaged.PageCount) | ||
return null; | ||
|
||
return listPaged; | ||
} | ||
|
||
// in this case we return IEnumerable<string>, but in most | ||
// - DB situations you'll want to return IQueryable<string> | ||
protected IEnumerable<string> GetStuffFromDatabase() | ||
{ | ||
public IActionResult Index(int page = 1) | ||
{ | ||
ViewBag.Names = GetPagedNames(page); | ||
return View(); | ||
} | ||
|
||
public IActionResult AjaxIndex(int page = 1) | ||
{ | ||
var listPaged = GetPagedNames(page); | ||
ViewBag.Names = listPaged; | ||
return View(); | ||
} | ||
|
||
public IActionResult GetOnePageOfNames(int page = 1) | ||
{ | ||
var listPaged = GetPagedNames(page); | ||
ViewBag.Names = listPaged; | ||
return PartialView("_NameListPartial", ViewBag.Names); | ||
} | ||
|
||
public IActionResult Error() | ||
{ | ||
return View(); | ||
} | ||
|
||
protected IPagedList<string> GetPagedNames(int? page) | ||
{ | ||
// return a 404 if user browses to before the first page | ||
if (page.HasValue && page < 1) | ||
return null; | ||
|
||
// retrieve list from database/whereverand | ||
var listUnpaged = GetStuffFromDatabase(); | ||
|
||
// page the list | ||
const int pageSize = 20; | ||
var listPaged = listUnpaged.ToPagedList(page ?? 1, pageSize); | ||
|
||
// return a 404 if user browses to pages beyond last page. special case first page if no items exist | ||
if (listPaged.PageNumber != 1 && page.HasValue && page > listPaged.PageCount) | ||
return null; | ||
|
||
return listPaged; | ||
} | ||
|
||
// in this case we return IEnumerable<string>, but in most | ||
// - DB situations you'll want to return IQueryable<string> | ||
protected IEnumerable<string> GetStuffFromDatabase() | ||
{ | ||
var sampleData = System.IO.File.ReadAllText("Names.txt"); | ||
return sampleData.Split('\n'); | ||
} | ||
var sampleData = System.IO.File.ReadAllText("Names.txt"); | ||
return sampleData.Split('\n'); | ||
} | ||
} |
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
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
Oops, something went wrong.