[英]display images in rss feeds using SyndicationItem class
我使用System.ServiceModel.Syndication創建rss feed
public ActionResult RSS()
{
List<C_Node> rssNodes = GetNodeList(takeNum: 20).ToList();
var syndItems = new List<SyndicationItem>();
foreach (var item in rssNodes)
{
var syndItem = new SyndicationItem()
{
Id = item.NodeId.ToString(),
Title = SyndicationContent.CreatePlaintextContent(String.Format("{0}", item.Title)),
Summary = SyndicationContent.CreateHtmlContent(HelperMethods.Truncate(item.Details,400)),
Content = SyndicationContent.CreateHtmlContent(item.Details),
PublishDate = item.PostDate
};
//syndItem.ElementExtensions.Add("content:encoded", "", SyndicationContent.CreateHtmlContent(item.Details));
syndItem.Links.Add(SyndicationLink.CreateAlternateLink(new Uri(ConfigurationManager.AppSettings["SiteUrl"] + Url.Action("Details", "Node", new { id = item.NodeId }))));//Nothing alternate about it. It is the MAIN link for the item.
syndItems.Add(syndItem);
}
return new RssFeed(title: Resources.Site.Title,
items: syndItems,
contentType: "application/rss+xml",
description: Resources.Site.Slogan);
}
我的問題是如何在每個聯合項目中顯示圖像?
添加此代碼完成:
syndItem.ElementExtensions.Add(new XElement("image", item.ImageUrl));
此代碼也有效
syndItem.ElementExtensions.Add(new XElement("enclosure", new XAttribute("type", "image/jpeg"), new XAttribute("url", item.ImageUrl).CreateReader());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.