简体   繁体   English

自定义RSS阅读器为Asp.net MVC

[英]Custom RSS Reader for Asp.net MVC

I need below kind of out put after reading the rss feed from the blog feed. 从博客提要中读取rss提要之后,我需要以下输出方式。

在此处输入图片说明

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 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 ? 更新的问题:如何获取没有html标记的描述?

Your content type is application/rss+xml . 您的内容类型为application/rss+xml In that way it will never show up as html. 这样,它将永远不会显示为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. 只需删除ContentType="application/rss+xml"部分或将其替换为text/html然后将页面更改为html而不是rss。

There is no way to tell the browser: hey, you should read rss but format it like html. 没有办法告诉浏览器:嘿,您应该阅读rss,但将其格式化为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). 您可以组合事物 (因此html中的rss标签),但是它将评估浏览器的最佳思考方式(而这并不是您想要的)。

Just output html from your rss reading and format it as html. 只需从您的RSS阅读器输出html并将其格式化为html。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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