I'm really rusty when it comes to coding and have worked hard to find the answer, but I'm on my whits end right now.
My website has a database with stored RSS URLs. For life, I cannot figure out how to scroll and display all the data from RSS feeds.
I can get one channel to show it just fine, but showing all of them, I just donβt know what to do to display all of them. Any help would be greatly appreciated!
Model: RSS.cs
namespace MyWebsite.Models { public class RSS { public string Link { get; set; } public string Title { get; set; } public string Description { get; set; } public string PubDate { get; set; } public string Date { get; set; } } }
Model: RSSReader.cs
namespace MyWebsite.Models { public class RSSReader { private static string _URL = ""; public static IEnumerable<RSS> GetRSSFeed() { IEnumerable<RSS> feeds = null; XDocument feedXml = null; XNamespace rss = "http://purl.org/rss/1.0/"; XNamespace dc = "http://purl.org/dc/elements/1.1/"; int count = 0; foreach (var url in BansheeData.GetURL(count)) { _URL = url.url1; feedXml = XDocument.Load(_URL); feeds = from feed in feedXml.Descendants(rss + "item") select new RSS { Title = feed.Element(rss + "title").Value, Link = feed.Element(rss + "link").Value, Date = feed.Element(dc + "date").Value.Remove(10) }; count++; } return feeds; } } }
Controller: RSSController.cs
public ActionResult Index() { var urlFeed = MyWebsite.Models.RSSReader.GetRSSFeed(); return View(urlFeed); }
View: _RSSFeed.cshtml
@model IEnumerable<MyWebsite.Models.RSS> @foreach (var item in Model) { <section> <header class="overflow"> <h1> <a href="@item.Link" target="_blank" class="alt overflow"> <span class="fl">@Html.Raw(item.Title)</span> <span class="ref fr">Source, @Html.Encode(item.Date)</span> </a> </h1> </header> </section> }
source share