从我的 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