0

从我的 rss 提要中检索图像时,我被困在如何实现分页。我还有一个助手来呈现寻呼机链接的 html。但是我不确定在索引操作中该怎么做。我的代码如下:

在我的控制器中:

Public Function Index() As ActionResult
        Dim feedurl As String = "http://riderdesign.net/p290530166/recent.rss"
        Using x = XmlReader.Create(feedurl)
            Dim r = XDocument.Load(x)
            Dim mediapfx As XNamespace = "http://search.yahoo.com/mrss/"
            '  Dim rssfeed = SyndicationFeed.Load(x)
            Dim ml = From item In r.Descendants(mediapfx + "content") Select item
            Dim PageSize As Integer = Configuration.ConfigurationManager.AppSettings.Get("PageSize")

            Dim medialist = From item In r.Descendants("item") Select New MediaImage With {
             .Alt = item.Element("title"), .ImageUrl = item.Element("link"), .ThumbnailUrl = TryGetAttributeValue(item.Element(mediapfx + "thumbnail"), "url"), .Height = TryGetAttributeValue(item.Element(mediapfx + "thumbnail"), "height"), .Width = TryGetAttributeValue(item.Element(mediapfx + "thumbnail"), "width")} Take PageSize
            Return View(medialist)

        End Using

    End Function

PagedData 类:

    Public Class PagedData
    Public Property TotalItems As Integer

    Public Property ItemsPerPage As Integer

    Public Property CurrentPage As Integer

    ReadOnly Property TotalPages As Integer
        Get
            Return Convert.ToInt32(Math.Ceiling(Convert.ToDecimal(TotalItems / ItemsPerPage)))
        End Get
    End Property

End Class

还有我的分页视图模型

 mvcPublic Class PagingViewModel
    Property Images As IEnumerable(Of MediaImage)
    Property Paging As Pager

End Class

分页助手:

   Public Class PagingHelper
    Public Shared Function PageLinks(ByVal html As HtmlHelper, ByVal Page As Pager, ByVal pageUrl As Func(Of Integer, String)) As MvcHtmlString
        Dim r As StringBuilder = New StringBuilder
        For i = 1 To Page.TotalPages
            Dim tag As TagBuilder = New TagBuilder("a")
            tag.MergeAttribute("href", pageUrl(i))
            tag.InnerHtml = i.ToString
            If i = Page.CurrentPage Then
                tag.AddCssClass("selected")
                r.Append(tag.ToString)

            End If
            Return MvcHtmlString.Create(r.ToString)
        Next

    End Function
4

2 回答 2

0

我建议,在您的视图中创建一个表并将 YUI 脚本添加到您的视图中。我使用它,它非常快。看看演示:http ://beckelman.net/post/2008/10/23/Client-Side-Table-Sorting-Paging-and-Filtering-with-jQuery-Demo.aspx

于 2011-11-23T02:24:11.807 回答
0

I implemented paging using Troy Goode's PagedList and its associated helper. I call the ToPagedList extension method and use the helper to render the links for paging. I did download the souce for the helper and modify it however to render spans instead of an unordered list for the paging links.

于 2011-12-05T22:04:05.337 回答