Question

I have a PagedList on one of my actions such as

 public ActionResult search(int? page)
     {

     }

The PagedList works correctly but my question is how can I findout what page the user is in and then change the background color on that page? for instance the PagedList at the bottom of the page are shown like


1 2 3 4 5


If the user is on like page 3 I would like to change the background color of the link that shows that page number, here is how my view is..

   @if (Model.HasPreviousPage)
    {
                  if (Model.PageNumber > 1)
              {
                @Html.ActionLink(String.Format("{0}", (Model.PageNumber - 1).ToString()), "index", new { page = Model.PageNumber - 1 })
                @Html.Raw(" ");
              }



    }

    @if (Model.HasNextPage)
    {



        if (Model.PageNumber + 1 <= Model.PageCount)
        {
            @Html.ActionLink(String.Format("{0}", (Model.PageNumber + 1).ToString()), "index", new { page = Model.PageNumber + 1 })
            @Html.Raw(" ")
        }

    }

The page number in the browser are shown as /search?page1 .../search?page2 etc. anyways any help or suggestions would be great !!

Was it helpful?

Solution

Change the styling of the link if the page link being rendered is the current page.

You don't show how you render the entire "pager bar", but we do something similar:

for (int i = 1; i <= Model.PageCount; i++)
{
    if (i == Model.PageNumber)
    {
        //this is the current page, so change the style of the link
        @Html.ActionLink(String.Format("{0}", i.ToString()), "index", new { page = i, style = "style_of_current_page_link" })
    }
    else
    {
        //this is not the current page, so 
        @Html.ActionLink(String.Format("{0}", i.ToString()), "index", new { page = i })
    }
    @Html.Raw(" ")
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top