我正在尝试从一个网站获取RSS源,并使用转发器在我的网站上显示它。但是当我在下面的代码中使用“Feeds”时,我就会收到一条错误消息:
private void PopulateRssFeed()
{
string RssFeedUrl = "http://timesofindia.feedsportal.com/c/33039/f/533965/index.rss";
List<Feeds> feeds = new List<Feeds>();
try
{
XDocument xDoc = new XDocument();
xDoc = XDocument.Load(RssFeedUrl);
var items = (from x in xDoc.Descendants("item")
select new
{
title = x.Element("title").Value,
link = x.Element("link").Value,
pubDate = x.Element("pubDate").Value,
description = x.Element("description").Value
});
if (items != null)
{
foreach (var i in items)
{
Feeds f = new Feeds
{
Title = i.title,
Link = i.link,
PublishDate = i.pubDate,
Description = i.description
};
feeds.Add(f);
}
}
rssRepeater.DataSource = feeds;
rssRepeater.DataBind();
}
catch (Exception ex)
{
throw;
}
}我在以下几行得到了错误
List<Feeds> feeds = new List<Feeds>();
Feeds f = new Feeds;Feed类如下:
namespace MumbaiLyst
{
public class Feeds
{
public string Title { get; set; }
public string Link { get; set; }
public string PublishDate { get; set; }
public string Description { get; set; }
}
}这是中继器的样子:
<asp:Repeater ID = "rssRepeater" runat = "server">
<ItemTemplate>
<table width="100%" border="0" cellpadding="0" cellspacing="5">
<tr>
<td>
<h3 style="color:#3E7CFF"><%#Eval("Title") %></h3>
</td>
<td width="200px">
<%#Eval("PublishDate") %>
</td>
</tr>
<tr>
<td colspan="2">
<hr />
<%#Eval("Description") %>
</td>
</tr>
<tr>
<td> </td>
<td align="right">
<a href='<%#Eval("Link") %>' target="_blank">Read More...</a>
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>发布于 2014-08-03 02:37:33
代码对我来说运行得很好。我将所有代码放在一个Default.aspx.cs文件中。Feed类位于同一命名空间中的同一文件中。代码本身没有问题。
如果不知道项目的结构,就不可能给出代码无法看到Feed类的确切原因。
https://stackoverflow.com/questions/25091663
复制相似问题