Created
August 4, 2015 18:46
-
-
Save mombrea/2892d5442c0688ccf403 to your computer and use it in GitHub Desktop.
Razor view for paging and sorting a table
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
@model PagedList.IPagedList<My.App.Model> | |
@using PagedList.Mvc; | |
@{ | |
ViewBag.Title = "Title"; | |
string currentFilter = ViewBag.CurrentFilter; | |
string currentSort = ViewBag.CurrentSort; | |
if (string.IsNullOrEmpty(currentSort)) | |
{ | |
currentSort = "date_desc"; | |
} | |
} | |
<div class="wrapper"> | |
<div class="search-box"> | |
<form class="form-inline"> | |
<div class="form-group"> | |
<input type="text" name="q" value="@ViewBag.searchQuery" class="search-text form-control" placeholder="Search..." /> | |
</div> | |
<button type="submit" class="btn btn-info">Search</button> | |
</form> | |
</div> | |
<div class="table-responsive"> | |
<table class="table table-striped table-condensed table-hover"> | |
<tr> | |
<th> | |
@Html.ActionLink("name", "Index", Request.QueryString.ToRouteValueDictionary("sortOrder", (string)ViewBag.NameSortParam)) | |
@Html.SortIdentifier(currentSort, "name") | |
</th> | |
<th> | |
@Html.ActionLink("Address", "Index", Request.QueryString.ToRouteValueDictionary("sortOrder", (string)ViewBag.AddressSortParam)) | |
@Html.SortIdentifier(currentSort, "address") | |
</th> | |
<th> | |
@Html.ActionLink("Date", "Index", Request.QueryString.ToRouteValueDictionary("sortOrder", (string)ViewBag.DateSortParam)) | |
@Html.SortIdentifier(currentSort, "date") | |
</th> | |
</tr> | |
<tbody> | |
@foreach (var item in Model) | |
{ | |
<tr> | |
<td> | |
@Html.DisplayFor(modelItem => item.name) | |
</td> | |
<td> | |
@Html.DisplayFor(modelItem => item.address) | |
</td> | |
<td> | |
@Html.DisplayFor(modelItem => item.date) | |
</td> | |
</tr> | |
} | |
</tbody> | |
</table> | |
</div> | |
@if (Model.PageCount > 1) | |
{ | |
<div class="pager"> | |
@Html.PagedListPager(Model, page => Url.Action("Index", new | |
{ | |
page, | |
sortOrder = ViewBag.currentSort, | |
q = currentSearch | |
})) | |
Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount | |
</div> | |
} | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, nice helper what does the controller or helper look like, is it taking an argument.
thnaks