使用SyndicationItem类在RSS提要中显示图片

3
我使用System.ServiceModel.Syndication创建RSS订阅源。
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);
}

我的问题是如何在每个聚合项中显示图片?

2个回答

5
完成添加此代码后:
syndItem.ElementExtensions.Add(new XElement("image", item.ImageUrl));

3
这段代码也可以正常工作。
syndItem.ElementExtensions.Add(new XElement("enclosure", new XAttribute("type", "image/jpeg"), new XAttribute("url", item.ImageUrl).CreateReader());

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接