简体   繁体   中英

Custom RSS Reader for Asp.net MVC

I need below kind of out put after reading the rss feed from the blog feed.

在此处输入图片说明

I have written below code snippet for that.

private IEnumerable<RssReader> GetBlogRssFeeds()
        {

           var rssFeed = XDocument.Load("http://sampathloku.blogspot.com/feeds/posts/default?alt=rss");

             var rssFeedOut= from item in rssFeed.Descendants("item")
               select new RssReader
               {
                   Title = item.Element("title").Value,
                   Link = item.Element("link").Value,
                   Description = (item.Element("description") != null) ? Regex.Match(item.Element("description").Value, @"^.{1,180}\b(?<!\s)").Value : ""
               };

        return rssFeedOut;
        }

View

<%@ Page Title="" ContentType="text/html" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<RssReader>>" %>

    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">


    <table border="1">

    <% foreach (var p in Model)
       { %>
    <tr border="1">
        <th>
            <%= Html.Encode(p.Title) %>
        </th>
    </tr>
    <tr border="1">
        <th>
            <%= Html.Encode(p.Description) %>
        </th>
    </tr>
    <tr border="1">
        <th>
            <%= Html.Encode(p.Link) %>
        </th>
    </tr>
    <% } %>
</table>
           </asp:Content>

But my Final out put shows everything is as below.

在此处输入图片说明

UPDATE

Now my View is as below.

在此处输入图片说明

My Question : How can I show Images and content are as above image ?

Updated Question : How can I get the description without html tags ?

Your content type is application/rss+xml . In that way it will never show up as html.

Just remove the ContentType="application/rss+xml" part or replace it with text/html and change your page to be html instead of rss.

There is no way to tell the browser: hey, you should read rss but format it like html. You can combine things (so rss tags in your html), but it will evaluate the way the browser thinks best (and that is not what you want).

Just output html from your rss reading and format it as html.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM