I'm very stupid and I can’t understand how to save the result of each loop pass in the array or in the sheet or in the collection, and only then pass it to the View. Accordingly, the controller code:
foreach (var k in db.Sources.Where(c => c.id != null).Select(c => c.URL)) { //какая то логика var RSSFeedData = (from x in xml.Descendants("item") select new RSSFeed { Title = (string)x.Element("title"), Link = (string)x.Element("link"), RSSName = (string)x.Element("Name"), PubDate = (string)x.Element("pubDate") }); ViewBag.RSSFeed = RSSFeedData; } return view();
I tried this: ViewBag.RSSFeed = ViewBag.RSSFeed.Add(RSSFeedData);
does not work. I tried to create an array, with the string type, but I also could not assign RSSFeed there. with the sheet is the same.
<tbody> @foreach (var item in ViewBag.RSSFeed) { <tr> <td><a href="@item.Link">@item.Title</a></td> <td>@item.RSSName</td> <td>@item.PubDate</td> </tr> } </tbody>