MVC 3 RSS Reader

Model

public class Feed
{
	public string Title { get; set; }
	public string Link { get; set; }
	public string Description { get; set; }
}

Controller

public ActionResult Index()
{

	XDocument feedXML = XDocument.Load("http://feeds.haacked.com/haacked");

	//select out a collection of anonymous types from RSS feed
	var feedCollection = from rss in feedXML.Descendants("item")
                select new Feed
                {
                    Title = rss.Element("title").Value,
                    Link = rss.Element("link").Value,
                    Description = rss.Element("description").Value
                };

    return View(feedCollection);
}

View

@model IEnumerable<RssReader.Models.Feed>
@{
	ViewBag.Title = "Index";
}

<h2>Index</h2>

<ul>
@foreach (var item in Model)
{
	<li>@item.Title</li>

}
</ul>
comments powered by Disqus