我被困在如何实现分页时,从我的rss提要检索图像。我还有一个帮助器来呈现寻呼机链接的html。然而,我不确定在索引行动中该怎么做。我的代码如下:
In my controller:
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
我建议,在视图中创建一个表,并向视图添加YUI脚本。我用过,非常快。看一下demo: http://beckelman.net/post/2008/10/23/Client-Side-Table-Sorting-Paging-and-Filtering-with-jQuery-Demo.aspx
我使用Troy Goode的PagedList及其相关的帮助器实现了分页。我调用ToPagedList扩展方法,并使用帮助器呈现用于分页的链接。我下载了帮助器的源代码,并对其进行了修改,使其呈现跨度,而不是分页链接的无序列表。