asp.net mvc - Looping through model of RSS feeds in mvc razor -
i'm generating list of rss links in model want show on webpage. model works fine , display of links works fine on view. question this, i'd display links in 2 side side columns. first 5 links in first column , next 5 links in second column. right i'm showing 10 links in each column. i'm sure there easy way this, i'm not sure how. appreciated.
here model:
namespace oa.models { public class rss1 { public string link { get; set; } public string title { get; set; } public string description { get; set; } } public class rss1reader { private static string _blogurl = "http://www.test.com/blogs/news/feed/"; public static ienumerable<rss1> getrss1feed() { xdocument feedxml = xdocument.load(_blogurl); var feeds = feed in feedxml.descendants("item") select new rss1 { title = feed.element("title").value, link = feed.element("link").value, description = regex.match(feed.element("description").value, @"^.{1,180}\b(?<!\s)").value }; return feeds; } }
}
here view:
@model ienumerable<oa.models.rss1> <table style="width: 80%;margin-left: auto;margin-right: auto;margin-top:10px;margin-bottom:25px;"> <tr> <td> <div id="rsscol1"> <span style="font-size:.9em;"> @foreach (var item in model) { <a href="@item.link" target="_blank">@item.title</a><br /> } </span> </div> </td> <td> <div id="rsscol2"> <span style="font-size:.9em;"> @foreach (var item in model) { <a href="@item.link" target="_blank">@item.title</a><br /> } </span> </div> </td> </tr> </table>
the quickest way accomplish update first , second loops this...
@foreach (var item in model.take(model.count()/2)) ... @foreach (var item in model.skip(model.count()/2))
however, might want consider 1 loop displays unordered list, using css lay out columns. if looking @ page on phone vs 27-inch screen? may want columns display differently. luck! see link: how display unordered list in 2 columns?
Comments
Post a Comment