【问题标题】:mvc3 pagedlist background selectionmvc3 pagedlist背景选择
【发布时间】:2014-01-29 01:40:49
【问题描述】:

我有一个 PagedList 用于我的一项操作,例如

 public ActionResult search(int? page)
     {

     }

PagedList 工作正常,但我的问题是如何找出用户所在的页面,然后更改该页面的背景颜色?例如页面底部的 PagedList 显示为


1 2 3 4 5


如果用户在第 3 页上,我想更改显示该页码的链接的背景颜色,这就是我的视图..

   @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(" ")
        }

    }

浏览器中的页码显示为 /search?page1 .../search?page2 等。无论如何,任何帮助或建议都会很棒!

【问题讨论】:

    标签: asp.net-mvc-3 pagination pagedlist page-numbering


    【解决方案1】:

    如果正在呈现的页面链接是当前页面,则更改链接的样式。

    你没有展示你如何渲染整个“pager bar”,但我们做了类似的事情:

    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(" ")
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-11-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多