https://www.nuget.org/packages?q=x.pagedlist
@using X.PagedList;
@using X.PagedList.Mvc;
@model X.PagedList.IPagedList<JQueryValidationPluginFinal.Models.User>
@{
ViewBag.Title = "PagingEx";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<link href="~/Content/PagedList.css" rel="stylesheet" />
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "CreateNew1")
</p>
<p>
Total Emps: @Model.TotalItemCount
</p>
<table class="table">
<tr>
<th>
@Html.ActionLink("Department", "PagingEx", new { sortOrder = "Department", CurrentSort = ViewBag.CurrentSort
})
</th>
<th>
@Html.ActionLink("FirstName", "PagingEx", new { sortOrder = "FirstName", CurrentSort = ViewBag.CurrentSort
})
</th>
<th>
@Html.DisplayNameFor(model
=> model.FirstOrDefault().LastName)
</th>
<th>
@Html.DisplayNameFor(model
=> model.FirstOrDefault().UserName)
</th>
<th>
@*@Html.DisplayNameForModel(model
=> model.Password)*@
</th>
<th>
@Html.DisplayNameFor(model
=> model.FirstOrDefault().ConfirmPassword)
</th>
<th>
@Html.ActionLink("EmailID", "PagingEx", new { sortOrder = "EmailID", CurrentSort = ViewBag.CurrentSort
})
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem
=> item.Department.Name)
</td>
<td>
@Html.DisplayFor(modelItem
=> item.FirstName)
</td>
<td>
@Html.DisplayFor(modelItem
=> item.LastName)
</td>
<td>
@Html.DisplayFor(modelItem
=> item.UserName)
</td>
<td>
@*@Html.DisplayFor(modelItem
=> item.Password)*@
</td>
<td>
@Html.DisplayFor(modelItem
=> item.ConfirmPassword)
</td>
<td>
@Html.DisplayFor(modelItem
=> item.EmailID)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.UserID }) |
@Html.ActionLink("Details", "Details", new { id = item.UserID }) |
@Html.ActionLink("Delete", "Delete", new { id = item.UserID })
</td>
</tr>
}
<tr>
<td colspan="4">
@*<div
id='Paging'>*@
Page @(Model.PageCount
< Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount
@Html.PagedListPager(Model,
page => Url.Action("PagingEx", new { page
}), PagedListRenderOptions.ClassicPlusFirstAndLast)
Showing @Model.FirstItemOnPage to @Model.LastItemOnPage
of @Model.TotalItemCount records.
@*</div>*@
</td>
</tr>
</table>
public ActionResult PagingEx(string sortOrder, string CurrentSort, int? page)
{
int
pageSize = 10;
int
pageIndex = 1;
pageIndex = page.HasValue ? Convert.ToInt32(page) : 1;
ViewBag.CurrentSort = sortOrder;
sortOrder = String.IsNullOrEmpty(sortOrder) ? "UserID" : sortOrder;
var users =
(from u in
db.User.Include(d => d.Department) select u);
IPagedList<JQueryValidationPluginFinal.Models.User>
usersList = null;
switch (sortOrder)
{
case "UserID":
if (sortOrder.Equals(CurrentSort))
usersList =
users.OrderByDescending(m => m.UserID).ToPagedList(pageIndex, pageSize);
else
usersList =
users.OrderBy(m => m.UserID).ToPagedList(pageIndex, pageSize);
break;
case "FirstName":
if (sortOrder.Equals(CurrentSort))
usersList =
users.OrderByDescending(m => m.FirstName).ToPagedList(pageIndex, pageSize);
else
usersList =
users.OrderBy(m => m.FirstName).ToPagedList(pageIndex, pageSize);
break;
case "Department":
if (sortOrder.Equals(CurrentSort))
usersList =
users.OrderByDescending(m => m.Department.Name).ToPagedList(pageIndex,
pageSize);
else
usersList =
users.OrderBy(m => m.Department.Name).ToPagedList(pageIndex, pageSize);
break;
case "EmailID":
if (sortOrder.Equals(CurrentSort))
usersList =
users.OrderByDescending(m => m.EmailID).ToPagedList(pageIndex, pageSize);
else
usersList =
users.OrderBy(m => m.EmailID).ToPagedList(pageIndex, pageSize);
break;
}
return View(usersList);
}
0 comments:
Post a Comment