lexeme
lexeme

Reputation: 2973

PagedList didn't render properly

I installed PagedList and PagedList.Mvc packages via NuGet. Then I used it in the manner:

@using PagedList;
@using PagedList.Mvc;

@model IPagedList<Employee>

@{
    ViewBag.Title = "ListEmployees";
}

<h3>All Employees (@ViewBag.TotalEmployees)</h3>

@if(Model.Count > 0)
{
    foreach(var item in Model)
    {
        Html.RenderPartial("Employee.Card", item);
    }

    @Html.PagedListPager((IPagedList)Model, page => Url.Action("List", new { page = page }), PagedListRenderOptions.Minimal)
}
else
{
    @: no records were found. Sorry
}

with the code inside controller:

public class EmployeeController : Controller
{
    private IRepository<Employee> repository; 
    private Int32 PageSize = 10;

    public EmployeeController(IRepository<Employee> repository)
    {
        this.repository = repository;
    }

    public ActionResult List(Int32? page)
    {
        var set = repository.Get();
        ViewBag.TotalEmployees = set.Count();

        return View(set.ToPagedList(page ?? 1, PageSize));
    }
}

Is this normal to have unstyled unordered list as a result. And how then I apply my custom styling to the pager?

Thanks!

Upvotes: 0

Views: 2102

Answers (1)

Troy
Troy

Reputation: 1649

creator of the PagedList nuget package here.

To be honest, I'm not sure what is going on - it strikes me as quite odd. My best guess based upon the description you gave is that Url.Action("List", new {page = page}) is returning a null or empty value which is then causing the href attribute to not render. You could test this by adding the following code elsewhere in your view and making sure it returns a real URL:

<p>@Url.Action("List", new {page = 1})</p>

If that paragraph tag is empty, then the problem is most likely in your routing.

Upvotes: 4

Related Questions