0

I am at a loss for finding a solution to format the result passed to the View from the Controller after implementing SyndicationFeed to return RSS feed in XML form. There are countless solutions of how to use SyndicationFeed, but almost nothing regarding displaying this in a custom style. How might I accomplish this? Please help!

HomeController.cs

public RssActionResult Index()
    {
        SyndicationFeed mainFeed = new SyndicationFeed();

        foreach (var feed in GetRssFeeds())
        {
            Uri feedUri = new Uri(feed);
            SyndicationFeed syndicationFeed;
            using (XmlReader reader = XmlReader.Create(feedUri.AbsoluteUri))
            {
                syndicationFeed = SyndicationFeed.Load(reader);
            }

            syndicationFeed.Id = feed;
            SyndicationFeed tempFeed = new SyndicationFeed(
                mainFeed.Items.Union(syndicationFeed.Items).OrderByDescending(u => u.PublishDate));

            mainFeed = tempFeed;
        }

        return new RssActionResult() { Feed = mainFeed }; 
    }

public class RssActionResult : ActionResult
    {
        public SyndicationFeed Feed { get; set; }

        public override void ExecuteResult(ControllerContext context)
        {

            context.HttpContext.Response.ContentType = "application/rss+xml";
            Rss20FeedFormatter rssFormatter = new Rss20FeedFormatter(Feed);

            using (XmlWriter writer = XmlWriter.Create(context.HttpContext.Response.Output))
            {
                rssFormatter.WriteTo(writer);
            }
        }
    }

    private static List<string> GetRssFeeds()
    {
        List<string> feeds = new List<string>();

        feeds.Add("http://finance.yahoo.com/rss/headline?s=msft,goog,aapl");

        return feeds;
    }

How to style and display in the view? Preferably within something like the following

@{
ViewBag.Title = "RSS Feed";
}
<h2>@ViewBag.Title.</h2>
<h3>@ViewBag.Message</h3>

<section id="rssfeed">
    <div class="container-fluid">
        <div class="row">
            <div class="col-md-8">
                <h4>The Feed</h4>
                    @* DISPLAY FEED HERE FORMATTED NICELY *@
            </div>
         </div>
     </div>
</section>
4

0 回答 0