从我的RSS Feed中检索图像时,我仍然坚持如何处理分页。我还有一个帮助器来呈现寻呼机链接的html。但是我不确定在Index操作中该怎么做。我的代码如下:
在我的控制器中:
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
答案 0 :(得分:0)
我建议,在View中创建一个表并将YUI脚本添加到View.I使用它,它非常快。 看一下demo:http://beckelman.net/post/2008/10/23/Client-Side-Table-Sorting-Paging-and-Filtering-with-jQuery-Demo.aspx
答案 1 :(得分:0)
我使用Troy Goode的PagedList及其关联的帮助器实现了分页。我调用ToPagedList扩展方法并使用帮助器呈现分页链接。我确实下载了帮助程序的源并修改它,但是为了呈现跨度而不是分页链接的无序列表。