Click here to Skip to main content
15,902,276 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using Pagedlist for Pagination in my MVC project. Pagination is working for most of the cases. But in my FilterController and its View when i render pagination links are created but without any parameter value to querystring page.

All the Anchor Tags / href values are null and empty.

Here is my ViewModel
public class SearchResult
{
    public int ItemID { get; set; }
    public string ItemTitle { get; set; }
    public int? AuthorID { get; set; }
    public string AuthorName { get; set; }  
    public int? IssueDate { get; set; }
}


And ActionResult Method

public ActionResult Date(int? page)
{
    try
    {
        string query;
        if (Request.RequestContext.RouteData.Values["query"] != null)
        {
            using (dreposEntities db = new dreposEntities())
            {
                query = Request.RequestContext.RouteData.Values["query"].ToString();
                int issueYear = int.Parse(query);
                ViewBag.Query = issueYear;

                var dateFilter = db.itemstreams.Where(q => q.issuedate == issueYear).ToList();
                List<SearchResult> resultList = new List<SearchResult>();
                if (dateFilter.Any())
                {
                    foreach (var c in dateFilter)
                    {
                        SearchResult obj = new SearchResult
                        {
                            ItemID = c.id,
                            ItemTitle = c.title,
                            IssueDate = c.issuedate,
                        };
                        resultList.Add(obj);
                    }
                }
                ViewBag.SearchQuery = query;

                return View(resultList.OrderBy(d=>d.IssueDate).ToPagedList(page ?? 1, 10));
            }
        }
        else
        {
            using (dreposEntities db = new dreposEntities())
            {
                List<SearchResult> resultList = new List<SearchResult>();
                var files = db.itemstreams.Where(s=>s.status==1).ToList();
                if (files.Any())
                {
                    foreach (var f in files)
                    {
                        SearchResult obj = new SearchResult
                        {
                            ItemID = f.id,
                            ItemTitle = f.title,
                            IssueDate = f.issuedate,
                        };
                        resultList.Add(obj);
                    }
                }
                return View(resultList.OrderBy(d=>d.IssueDate).ToPagedList(page ?? 1, 10));
            }
        }
    }
    catch (Exception e)
    {
        return View();
    }
}


What I have tried:

And in my View to render Pagination Links

@Html.PagedListPager(Model, page => Url.Action("AllRecords", new { page, size = Model.PageSize }), new PagedListRenderOptions() { Display = PagedListDisplayMode.IfNeeded })



Pagination Links are generated but their href Anchor tags are empty / null
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900