2017-01-02 78 views
0

我創建使用System.ServiceModel.Syndication顯示圖像飼料使用SyndicationItem

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

與添加此代碼完成的:

syndItem.ElementExtensions.Add(new XElement("image", item.ImageUrl)); 
1

此代碼也正在

syndItem.ElementExtensions.Add(new XElement("enclosure", new XAttribute("type", "image/jpeg"), new XAttribute("url", item.ImageUrl).CreateReader());