I am trying to add pagination to my view and edited my controller to create it, but when I try to include the PagedList model I get an error as I can't include my original model. This is what my view looks like right now:
@model IEnumerable<metric_tool.Models.Metric>
@model PagedList.IPagedList<metric_tool.Models.Metric>
@using PagedList
@{
ViewBag.Title = "Metrics List";
}
<h2>Metrics</h2>
<p>
@Html.ActionLink("Create New", "Create")
@using (Html.BeginForm("Index", "Metric", FormMethod.Get))
{
<p>
Category: @Html.DropDownList("metricCategory","All")
Client: @Html.DropDownList("metricClient","All")
Phase: @Html.DropDownList("metricPhase","All")
Hierarchy: @Html.DropDownList("metricHierarchy", "All")
Thresholds: @Html.DropDownList("metricThreshold", "All") <br />
</p>
<p>
Data Source Search: @Html.TextBox("searchDataSrc") <input type="submit" value="Search" />
Description Search: @Html.TextBox("SearchString", ViewBag.CurrentFilter as string) <input type="submit" value="Search" />
</p>
}
</p>
<table class="table">
<tr>
<th>
@Html.ActionLink("Metric","Index", new { sortOrder = ViewBag.MetricSort, currentFilter=ViewBag.CurrentFilter })
</th>
<th>
@Html.ActionLink("Category", "Index", new { sortOrder = ViewBag.CategorySort, currentFilter = ViewBag.CurrentFilter })
</th>
<th>
@Html.DisplayNameFor(model => model.SelectClient)
</th>
<th>
@Html.DisplayNameFor(model => model.SelectPhase)
</th>
<th>
@Html.DisplayNameFor(model => model.SelectHierarchy)
</th>
<th>
@Html.DisplayNameFor(model => model.SelectDataSource)
</th>
<th>
@Html.DisplayNameFor(model => model.SelectThresholds)
</th>
<th>
@Html.DisplayNameFor(model => model.Description)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
.....
</table>
<br />
Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount
@Html.PagedListPager(Model, page => Url.Action("Index",
new { page, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter }))
I was looking at using a dynamic model, but wasn't able to get it to work instead.