Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- json #paramquery
- AWS
- advil
- 애드빌
- VLOOKUP
- vs2017
- 금융감독원API
- #알뜰폰
- 알뜰유심
- apple여의도
- 알뜰
- xml뷰어
- 유니콘
- 유니콘앱
- 유심무료
- OPENDART
- XML무료뷰어
- 소스비교
- VS2015
- productivity Power Tools
- 애드빌용법
- VS2019
- 여의도IFC
- SK7MOBILE
- xmlviewer
- 광고차단
- applestore
- 유니콘광고차단
- 알뜰요금제
- IFC
Archives
- Today
- Total
체크개발자's Blog
MVC - Paging (OrderBy -> Skip -> Take) 본문
OrderBy -> Skip -> Take
Controller
public ActionResult Index()
{
int maxListCount = 4;
int pageNum = 1;
if (Request.QueryString["page"] != null)
pageNum = Convert.ToInt32(Request.QueryString["page"]);
var books = db.Books.OrderBy(x => x.Book_U)
.Skip(maxListCount * (pageNum-1)).Take(maxListCount).ToList();
ViewBag.Page = pageNum;
ViewBag.TotalCount = db.Books.Count();
ViewBag.MaxListCount = maxListCount;
return View(books);
}
Index.cshtml
@{
ViewBag.Title = "Index";
int pageNum = ViewBag.Page ?? 1;
int totalCount = ViewBag.TotalCount ?? 0;
int maxListCount = ViewBag.MaxListCount ?? 1;
int totalPageCount = Convert.ToInt32( Math.Ceiling((double)totalCount / maxListCount));@* 좀 더 효율적인 방법이 없을까? *@
}
<div class="text-center">
<div class="btn-group">
@for (int i = 1; i <= totalPageCount; i++)
{
<a class="btn btn-@(pageNum == i ? "primary":"default")" href="?page=@i">@i</a>
}
@* 주석 <a class="btn btn-@(pageNum == 1 ? "primary":"default")" href="?page=1">1</a>
<a class="btn btn-@(pageNum == 2 ? "primary":"default")" href="?page=2">2</a>
<a class="btn btn-@(pageNum == 3 ? "primary":"default")" href="?page=3">3</a>*@
</div>
</div>
'프로그래밍 > C# .NET' 카테고리의 다른 글
[Visual Studio] Productivity Power Tools 이건 설치해야 해!!! (0) | 2021.03.23 |
---|---|
Excel 처리(Read, Write) 엑셀 파일 읽기 쓰기 (0) | 2021.01.02 |
OpenDART 연동 - 고유번호 (0) | 2020.12.02 |
OpenDART 연동 - 공시정보 기업개황 준비편 (0) | 2020.12.01 |
Repeater 에서 header와 Item hidden 처리(hide) (0) | 2017.11.10 |
Comments